Example #1
0
        /// <summary>
        /// Creates a new <see cref="RemoteRenderer"/>.
        /// </summary>
        public RemoteRenderer(
            IServiceProvider serviceProvider,
            ILoggerFactory loggerFactory,
            CircuitOptions options,
            CircuitClientProxy client,
            ILogger logger,
            RemoteJSRuntime jsRuntime,
            CircuitJSComponentInterop jsComponentInterop)
            : base(serviceProvider, loggerFactory, jsRuntime.ReadJsonSerializerOptions(), jsComponentInterop)
        {
            _client  = client;
            _options = options;
            _logger  = logger;

            ElementReferenceContext = jsRuntime.ElementReferenceContext;
        }
Example #2
0
        public async ValueTask <CircuitHost> CreateCircuitHostAsync(
            IReadOnlyList <ComponentDescriptor> components,
            CircuitClientProxy client,
            string baseUri,
            string uri,
            ClaimsPrincipal user,
            IComponentApplicationStateStore 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 <ComponentApplicationLifetime>();
            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,
                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);
        }