IConsumerScopeContext IConsumerScopeProvider.GetScope(ConsumeContext context) { if (context.TryGetPayload <ILifetimeScope>(out _)) { return(new ExistingConsumerScopeContext(context)); } var parentLifetimeScope = _scopeProvider.GetLifetimeScope(context); var lifetimeScope = parentLifetimeScope.BeginLifetimeScope(_name, builder => { builder.ConfigureScope(context); _configureScope?.Invoke(builder, context); }); try { var proxy = new ConsumeContextProxyScope(context); proxy.UpdatePayload(lifetimeScope); return(new CreatedConsumerScopeContext <ILifetimeScope>(lifetimeScope, proxy)); } catch { lifetimeScope.Dispose(); throw; } }
IConsumerScopeContext IConsumerScopeProvider.GetScope(ConsumeContext context) { if (context.TryGetPayload <IServiceScope>(out var existingServiceScope)) { existingServiceScope.UpdateScope(context); return(new ExistingConsumerScopeContext(context)); } if (!context.TryGetPayload(out IServiceProvider serviceProvider)) { serviceProvider = _serviceProvider; } var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope(); try { serviceScope.UpdateScope(context); var consumeContext = new ConsumeContextProxyScope(context); consumeContext.UpdatePayload(serviceScope); return(new CreatedConsumerScopeContext <IServiceScope>(serviceScope, consumeContext)); } catch { serviceScope.Dispose(); throw; } }
public IConsumerScopeContext GetScope(ConsumeContext context) { if (context.TryGetPayload <Scope>(out var existingScope)) { existingScope.UpdateScope(context); return(new ExistingConsumerScopeContext(context)); } var scope = AsyncScopedLifestyle.BeginScope(_container); try { scope.UpdateScope(context); var proxy = new ConsumeContextProxyScope(context); proxy.UpdatePayload(scope); return(new CreatedConsumerScopeContext <Scope>(scope, proxy)); } catch { scope.Dispose(); throw; } }
public IConsumerScopeContext GetScope(ConsumeContext context) { if (context.TryGetPayload <IKernel>(out var kernel)) { kernel.UpdateScope(context); return(new ExistingConsumerScopeContext(context)); } var scope = _kernel.CreateNewOrUseExistingMessageScope(context); try { var proxy = new ConsumeContextProxyScope(context); proxy.UpdatePayload(_kernel); foreach (Action <ConsumeContext> scopeAction in _scopeActions) { scopeAction(proxy); } return(new CreatedConsumerScopeContext <IDisposable>(scope, proxy)); } catch { scope?.Dispose(); throw; } }
public IConsumerScopeContext GetScope(ConsumeContext context) { if (context.TryGetPayload <INestedContainer>(out var existingContainer)) { existingContainer.Inject(context); return(new ExistingConsumerScopeContext(context)); } var nestedContainer = _container.GetNestedContainer(context); try { var proxy = new ConsumeContextProxyScope(context); proxy.UpdatePayload(nestedContainer); return(new CreatedConsumerScopeContext <INestedContainer>(nestedContainer, proxy)); } catch { nestedContainer.Dispose(); throw; } }