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; } }
public IConsumerScopeContext 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); 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; } }
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 <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 <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 <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; } }
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; } }