public override CircuitHost CreateCircuitHost(HttpContext httpContext, IClientProxy client)
        {
            if (!StartupActions.TryGetValue(httpContext.Request.Path, out var config))
            {
                var message = $"Could not find a Blazor startup action for request path {httpContext.Request.Path}";
                throw new InvalidOperationException(message);
            }

            var scope                  = _scopeFactory.CreateScope();
            var jsRuntime              = new RemoteJSRuntime(client);
            var rendererRegistry       = new RendererRegistry();
            var renderer               = new RemoteRenderer(scope.ServiceProvider, rendererRegistry, jsRuntime, client);
            var synchronizationContext = new CircuitSynchronizationContext();

            var circuitHost = new CircuitHost(
                scope,
                client,
                rendererRegistry,
                renderer,
                config,
                jsRuntime,
                synchronizationContext);

            // Initialize per-circuit data that services need
            (circuitHost.Services.GetRequiredService <IJSRuntimeAccessor>() as DefaultJSRuntimeAccessor).JSRuntime = jsRuntime;
            (circuitHost.Services.GetRequiredService <ICircuitAccessor>() as DefaultCircuitAccessor).Circuit       = circuitHost.Circuit;

            return(circuitHost);
        }
Exemple #2
0
        /// <summary>
        /// Sets the current <see cref="Circuit"/>.
        /// </summary>
        /// <param name="circuitHost">The <see cref="Circuit"/>.</param>
        /// <remarks>
        /// Calling <see cref="SetCurrentCircuitHost(CircuitHost)"/> will store the circuit
        /// and other related values such as the <see cref="IJSRuntime"/> and <see cref="Renderer"/>
        /// in the local execution context. Application code should not need to call this method,
        /// it is primarily used by the Server-Side Blazor infrastructure.
        /// </remarks>
        public static void SetCurrentCircuitHost(CircuitHost circuitHost)
        {
            if (circuitHost == null)
            {
                throw new ArgumentNullException(nameof(circuitHost));
            }

            _current.Value = circuitHost;

            Microsoft.JSInterop.JSRuntime.SetCurrentJSRuntime(circuitHost.JSRuntime);
            RendererRegistry.SetCurrentRendererRegistry(circuitHost.RendererRegistry);
        }
Exemple #3
0
 internal Circuit(CircuitHost circuitHost)
 {
     JSRuntime = circuitHost.JSRuntime;
     Services = circuitHost.Services;
 }