private CircuitHost GetOrCreateCircuitHost(HttpContext context, CircuitNavigationStatus navigationStatus) { 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; if (!navigationStatus.Navigated) { _registry.RegisterDisconnectedCircuit(result); } return(Task.CompletedTask); }); context.Items.Add(CircuitHostKey, result); return(result); } }
private CircuitNavigationStatus GetOrCreateNavigationStatus(HttpContext context) { if (context.Items.TryGetValue(NavigationStatusKey, out var existingHost)) { return((CircuitNavigationStatus)existingHost); } else { var navigationStatus = new CircuitNavigationStatus(); context.Items[NavigationStatusKey] = navigationStatus; return(navigationStatus); } }
private static async Task CleanupCircuitState(HttpContext context, CircuitNavigationStatus navigationStatus, CircuitHost circuitHost) { navigationStatus.Navigated = true; context.Items.Remove(CircuitHostKey); await circuitHost.DisposeAsync(); }