IConsumerScopeContext IConsumerScopeProvider.GetScope(ConsumeContext context) { if (context.TryGetPayload <IServiceScope>(out var existingServiceScope)) { return(new ExistingConsumerScopeContext(context)); } var scopeFactory = _serviceProvider.GetRequiredService <IServiceScopeFactory>(); var serviceScope = scopeFactory.CreateScope(); try { var proxy = new ConsumeContextProxyScope(context); var scope = serviceScope; proxy.GetOrAddPayload(() => scope); proxy.GetOrAddPayload(() => scope.ServiceProvider); return(new CreatedConsumerScopeContext <IServiceScope>(scope, proxy)); } catch { serviceScope.Dispose(); throw; } }
public IConsumerScopeContext GetScope(ConsumeContext context) { if (context.TryGetPayload <IContainer>(out var existingContainer)) { return(new ExistingConsumerScopeContext(context)); } var container = _container?.CreateNestedContainer(context) ?? _context?.CreateNestedContainer(context); try { var proxy = new ConsumeContextProxyScope(context); var consumerContainer = container; proxy.GetOrAddPayload(() => consumerContainer); return(new CreatedConsumerScopeContext <IContainer>(consumerContainer, proxy)); } catch { container.Dispose(); throw; } }
IConsumerScopeContext IConsumerScopeProvider.GetScope(ConsumeContext context) { if (context.TryGetPayload <ILifetimeScope>(out var existingLifetimeScope)) { return(new ExistingConsumerScopeContext(context)); } var parentLifetimeScope = _scopeProvider.GetLifetimeScope(context); var lifetimeScope = parentLifetimeScope.BeginLifetimeScope(_name, builder => builder.ConfigureScope(context)); try { var proxy = new ConsumeContextProxyScope(context); var scope = lifetimeScope; proxy.GetOrAddPayload(() => scope); return(new CreatedConsumerScopeContext <ILifetimeScope>(scope, proxy)); } catch { lifetimeScope.Dispose(); throw; } }
public IConsumerScopeContext GetScope(ConsumeContext context) { if (context.TryGetPayload <Scope>(out var existingScope)) { return(new ExistingConsumerScopeContext(context)); } var scope = AsyncScopedLifestyle.BeginScope(_container); try { var proxy = new ConsumeContextProxyScope(context); var consumerScope = scope; proxy.GetOrAddPayload(() => consumerScope); return(new CreatedConsumerScopeContext <Scope>(consumerScope, proxy)); } catch { scope.Dispose(); throw; } }
public IConsumerScopeContext GetScope(ConsumeContext context) { if (context.TryGetPayload <IUnityContainer>(out var existingScope)) { return(new ExistingConsumerScopeContext(context)); } var scope = _container.CreateChildContainer(); try { var proxy = new ConsumeContextProxyScope(context); var consumerScope = scope; proxy.GetOrAddPayload(() => consumerScope); return(new CreatedConsumerScopeContext <IUnityContainer>(consumerScope, proxy)); } catch { scope.Dispose(); throw; } }
public IConsumerScopeContext GetScope(ConsumeContext context) { IServiceScope payload; if (context.TryGetPayload <IServiceScope>(out payload)) { return((IConsumerScopeContext) new ExistingConsumerScopeContext(context)); } IServiceScope scope1 = SillycoreApp.Instance.ServiceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope(); try { ConsumeContextProxyScope contextProxyScope = new ConsumeContextProxyScope(context); IServiceScope scope = scope1; contextProxyScope.GetOrAddPayload <IServiceScope>((PayloadFactory <IServiceScope>)(() => scope)); return((IConsumerScopeContext) new CreatedConsumerScopeContext <IServiceScope>(scope, (ConsumeContext)contextProxyScope)); } catch { scope1.Dispose(); throw; } }