ISagaScopeContext <T> ISagaScopeProvider <TSaga> .GetScope <T>(ConsumeContext <T> context) { if (context.TryGetPayload <IServiceScope>(out var existingServiceScope)) { return(new ExistingSagaScopeContext <T>(context)); } var scopeFactory = _serviceProvider.GetRequiredService <IServiceScopeFactory>(); var scope = scopeFactory.CreateScope(); try { var proxy = new ConsumeContextProxy <T>(context, new PayloadCacheScope(context)); var sagaScope = scope; proxy.GetOrAddPayload(() => sagaScope); proxy.GetOrAddPayload(() => sagaScope.ServiceProvider); foreach (Action <ConsumeContext> scopeAction in _scopeActions) { scopeAction(proxy); } return(new CreatedSagaScopeContext <IServiceScope, T>(sagaScope, proxy)); } catch { scope.Dispose(); throw; } }
ISagaScopeContext <T> ISagaScopeProvider <TSaga> .GetScope <T>(ConsumeContext <T> context) { if (context.TryGetPayload <IUnityContainer>(out var existingScope)) { return(new ExistingSagaScopeContext <T>(context)); } var scope = _container.CreateChildContainer(); try { var proxy = new ConsumeContextProxy <T>(context, new PayloadCacheScope(context)); var consumerScope = scope; proxy.GetOrAddPayload(() => consumerScope); return(new CreatedSagaScopeContext <IUnityContainer, T>(consumerScope, proxy)); } catch { scope.Dispose(); throw; } }
ISagaScopeContext <T> ISagaScopeProvider <TSaga> .GetScope <T>(ConsumeContext <T> context) { if (context.TryGetPayload <ILifetimeScope>(out var existingLifetimeScope)) { return(new ExistingSagaScopeContext <T>(context)); } var parentLifetimeScope = _scopeProvider.GetLifetimeScope(context); var lifetimeScope = parentLifetimeScope.BeginLifetimeScope(_name, builder => builder.ConfigureScope(context)); try { var proxy = new ConsumeContextProxy <T>(context, new PayloadCacheScope(context)); var scope = lifetimeScope; proxy.GetOrAddPayload(() => scope); foreach (Action <ConsumeContext> scopeAction in _scopeActions) { scopeAction(proxy); } return(new CreatedSagaScopeContext <ILifetimeScope, T>(scope, proxy)); } catch { lifetimeScope.Dispose(); throw; } }
public ISagaScopeContext <T> GetScope <T>(ConsumeContext <T> context) where T : class { if (context.TryGetPayload <Scope>(out var existingScope)) { return(new ExistingSagaScopeContext <T>(context)); } var scope = AsyncScopedLifestyle.BeginScope(_container); try { var proxy = new ConsumeContextProxy <T>(context, new PayloadCacheScope(context)); var consumerScope = scope; proxy.GetOrAddPayload(() => consumerScope); return(new CreatedSagaScopeContext <Scope, T>(consumerScope, proxy)); } catch { scope.Dispose(); throw; } }
public ISagaScopeContext <T> GetScope <T>(ConsumeContext <T> context) where T : class { if (context.TryGetPayload <IContainer>(out var existingContainer)) { return(new ExistingSagaScopeContext <T>(context)); } var container = _container?.CreateNestedContainer(context) ?? _context?.CreateNestedContainer(context); try { var proxy = new ConsumeContextProxy <T>(context, new PayloadCacheScope(context)); var consumerContainer = container; proxy.GetOrAddPayload(() => consumerContainer); foreach (Action <ConsumeContext> scopeAction in _scopeActions) { scopeAction(proxy); } return(new CreatedSagaScopeContext <IContainer, T>(consumerContainer, proxy)); } catch { container.Dispose(); throw; } }
public ISagaScopeContext <T> GetScope <T>(ConsumeContext <T> context) where T : class { if (context.TryGetPayload <IKernel>(out _)) { return(new ExistingSagaScopeContext <T>(context)); } var scope = _container.BeginScope(); _container.Register(Component.For <ConsumeContext, ConsumeContext <T> >().Instance(context)); try { var proxy = new ConsumeContextProxy <T>(context, new PayloadCacheScope(context)); var consumerContainer = _container; proxy.GetOrAddPayload(() => consumerContainer); foreach (Action <ConsumeContext> scopeAction in _scopeActions) { scopeAction(proxy); } return(new CreatedSagaScopeContext <IDisposable, T>(scope, proxy)); } catch { scope.Dispose(); throw; } }
public static ConsumeContext <T> CreateScope <T, TScope>(this ConsumeContext <T> context, TScope scope) where T : class where TScope : class { var proxy = new ConsumeContextProxy <T>(context, new PayloadCacheScope(context)); proxy.GetOrAddPayload(() => scope); return(proxy); }