Beispiel #1
0
            // Implement a `CreateCircuitHostAsync` that mocks the construction
            // of the CircuitHost.
            public ValueTask <CircuitHost> CreateCircuitHostAsync(
                IReadOnlyList <ComponentDescriptor> components,
                CircuitClientProxy client,
                string baseUri,
                string uri,
                ClaimsPrincipal user,
                IComponentApplicationStateStore store)
            {
                var serviceScope = new Mock <IServiceScope>();
                var circuitHost  = TestCircuitHost.Create(serviceScope: new AsyncServiceScope(serviceScope.Object));

                return(ValueTask.FromResult(circuitHost));
            }
Beispiel #2
0
        public async ValueTask <CircuitHost> CreateCircuitHostAsync(
            IReadOnlyList <ComponentDescriptor> components,
            CircuitClientProxy client,
            string baseUri,
            string uri,
            ClaimsPrincipal user,
            IComponentApplicationStateStore store)
        {
            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 appLifetime = scope.ServiceProvider.GetRequiredService <ComponentApplicationLifetime>();
            await appLifetime.RestoreStateAsync(store);

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

            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);
        }