public async Task <IEnumerable <string> > PrerenderComponentAsync(ComponentPrerenderingContext prerenderingContext)
        {
            var context     = prerenderingContext.Context;
            var circuitHost = _circuitFactory.CreateCircuitHost(
                context,
                client: CircuitClientProxy.OfflineClient,
                GetFullUri(context.Request),
                GetFullBaseUri(context.Request));

            // We don't need to unsubscribe because the circuit host object is scoped to this call.
            circuitHost.UnhandledException += CircuitHost_UnhandledException;

            // For right now we just do prerendering and dispose the circuit. In the future we will keep the circuit around and
            // reconnect to it from the ComponentsHub. If we keep the circuit/renderer we also need to unsubscribe this error
            // handler.
            try
            {
                return(await circuitHost.PrerenderComponentAsync(
                           prerenderingContext.ComponentType,
                           prerenderingContext.Parameters));
            }
            finally
            {
                await circuitHost.DisposeAsync();
            }
        }
예제 #2
0
        private CircuitHost GetOrCreateCircuitHost(HttpContext context)
        {
            if (context.Items.TryGetValue(CircuitHostKey, out var existingHost))
            {
                return((CircuitHost)existingHost);
            }
            else
            {
                var result = _circuitFactory.CreateCircuitHost(
                    context,
                    client: new CircuitClientProxy(), // This creates an "offline" client.
                    GetFullUri(context.Request),
                    GetFullBaseUri(context.Request));

                result.UnhandledException += CircuitHost_UnhandledException;
                context.Response.OnCompleted(() =>
                {
                    result.UnhandledException -= CircuitHost_UnhandledException;
                    _registry.RegisterDisconnectedCircuit(result);
                    return(Task.CompletedTask);
                });
                context.Items.Add(CircuitHostKey, result);

                return(result);
            }
        }
예제 #3
0
        public async Task <IEnumerable <string> > PrerenderComponentAsync(ComponentPrerenderingContext prerenderingContext)
        {
            var context     = prerenderingContext.Context;
            var circuitHost = _circuitFactory.CreateCircuitHost(
                context,
                client: null,
                GetFullUri(context.Request),
                GetFullBaseUri(context.Request));

            // For right now we just do prerendering and dispose the circuit. In the future we will keep the circuit around and
            // reconnect to it from the ComponentsHub.
            try
            {
                return(await circuitHost.PrerenderComponentAsync(
                           prerenderingContext.ComponentType,
                           prerenderingContext.Parameters));
            }
            finally
            {
                await circuitHost.DisposeAsync();
            }
        }