示例#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,
            IPersistentComponentStateStore store)
        {
            var serviceScope = new Mock <IServiceScope>();
            var circuitHost  = TestCircuitHost.Create(serviceScope: new AsyncServiceScope(serviceScope.Object));

            return(ValueTask.FromResult(circuitHost));
        }
示例#2
0
    public async ValueTask <CircuitHost> CreateCircuitHostAsync(
        IReadOnlyList <ComponentDescriptor> components,
        CircuitClientProxy client,
        string baseUri,
        string uri,
        ClaimsPrincipal user,
        IPersistentComponentStateStore store)
    {
        var scope     = _scopeFactory.CreateAsyncScope();
        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 <ComponentStatePersistenceManager>();
        await appLifetime.RestoreStateAsync(store);

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

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

        var circuitHost = new CircuitHost(
            _circuitIdFactory.CreateCircuitId(),
            scope,
            _options,
            client,
            renderer,
            components,
            jsRuntime,
            navigationManager,
            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);
    }