Example #1
0
        public CircuitHost CreateCircuitHost(
            IReadOnlyList <ComponentDescriptor> components,
            CircuitClientProxy client,
            string baseUri,
            string uri,
            ClaimsPrincipal user)
        {
            var scope     = _scopeFactory.CreateScope();
            var jsRuntime = (RemoteJSRuntime)scope.ServiceProvider.GetRequiredService <IJSRuntime>();

            jsRuntime.Initialize(client);

            var navigationManager      = (RemoteNavigationManager)scope.ServiceProvider.GetRequiredService <NavigationManager>();
            var navigationInterception = (RemoteNavigationInterception)scope.ServiceProvider.GetRequiredService <INavigationInterception>();

            if (client.Connected)
            {
                navigationManager.AttachJsRuntime(jsRuntime);
                navigationManager.Initialize(baseUri, uri);

                navigationInterception.AttachJSRuntime(jsRuntime);
            }
            else
            {
                navigationManager.Initialize(baseUri, uri);
            }

            var renderer = new RemoteRenderer(
                scope.ServiceProvider,
                _loggerFactory,
                _options,
                client,
                _loggerFactory.CreateLogger <RemoteRenderer>());

            var circuitHandlers = scope.ServiceProvider.GetServices <CircuitHandler>()
                                  .OrderBy(h => h.Order)
                                  .ToArray();

            var circuitHost = new CircuitHost(
                _circuitIdFactory.CreateCircuitId(),
                scope,
                _options,
                client,
                renderer,
                components,
                jsRuntime,
                circuitHandlers,
                _loggerFactory.CreateLogger <CircuitHost>());

            Log.CreatedCircuit(_logger, circuitHost);

            // Initialize per - circuit data that services need
            (circuitHost.Services.GetRequiredService <ICircuitAccessor>() as DefaultCircuitAccessor).Circuit = circuitHost.Circuit;
            circuitHost.SetCircuitUser(user);

            return(circuitHost);
        }
Example #2
0
        public CircuitHost(
            CircuitId circuitId,
            IServiceScope scope,
            CircuitOptions options,
            CircuitClientProxy client,
            RemoteRenderer renderer,
            IReadOnlyList <ComponentDescriptor> descriptors,
            RemoteJSRuntime jsRuntime,
            CircuitHandler[] circuitHandlers,
            ILogger logger)
        {
            CircuitId = circuitId;
            if (CircuitId.Secret is null)
            {
                // Prevent the use of a 'default' secret.
                throw new ArgumentException(nameof(circuitId));
            }

            _scope           = scope ?? throw new ArgumentNullException(nameof(scope));
            _options         = options ?? throw new ArgumentNullException(nameof(options));
            Client           = client ?? throw new ArgumentNullException(nameof(client));
            Renderer         = renderer ?? throw new ArgumentNullException(nameof(renderer));
            Descriptors      = descriptors ?? throw new ArgumentNullException(nameof(descriptors));
            JSRuntime        = jsRuntime ?? throw new ArgumentNullException(nameof(jsRuntime));
            _circuitHandlers = circuitHandlers ?? throw new ArgumentNullException(nameof(circuitHandlers));
            _logger          = logger ?? throw new ArgumentNullException(nameof(logger));

            Services = scope.ServiceProvider;

            Circuit = new Circuit(this);
            Handle  = new CircuitHandle()
            {
                CircuitHost = this,
            };

            Renderer.UnhandledException += Renderer_UnhandledException;
            Renderer.UnhandledSynchronizationException += SynchronizationContext_UnhandledException;
        }