public ISendScopeContext <T> GetScope <T>(SendContext <T> context) where T : class { if (context.TryGetPayload <IServiceScope>(out _)) { return(new ExistingSendScopeContext <T>(context)); } if (!context.TryGetPayload(out IServiceProvider serviceProvider)) { serviceProvider = _serviceProvider; } var serviceScope = serviceProvider.CreateScope(); try { var sendContext = new SendContextScope <T>(context, serviceScope, serviceScope.ServiceProvider); return(new CreatedSendScopeContext <IServiceScope, T>(serviceScope, sendContext)); } catch { serviceScope.Dispose(); throw; } }
public ISendScopeContext <T> GetScope <T>(SendContext <T> context) where T : class { if (context.TryGetPayload <IKernel>(out _)) { return(new ExistingSendScopeContext <T>(context)); } var scope = _kernel.CreateNewMessageScope(context); try { var sendContext = new SendContextScope <T>(context, _kernel); return(new CreatedSendScopeContext <IDisposable, T>(scope, sendContext)); } catch { scope?.Dispose(); throw; } }
public ISendScopeContext <T> GetScope <T>(SendContext <T> context) where T : class { if (context.TryGetPayload <IContainer>(out _)) { return(new ExistingSendScopeContext <T>(context)); } var nestedContainer = _container?.CreateNestedContainer(context) ?? _context?.CreateNestedContainer(context); try { var sendContext = new SendContextScope <T>(context, nestedContainer); return(new CreatedSendScopeContext <IContainer, T>(nestedContainer, sendContext)); } catch { nestedContainer.Dispose(); throw; } }
public ISendScopeContext <T> GetScope <T>(SendContext <T> context) where T : class { if (context.TryGetPayload <Scope>(out _)) { return(new ExistingSendScopeContext <T>(context)); } var scope = AsyncScopedLifestyle.BeginScope(_container); try { var sendContext = new SendContextScope <T>(context, scope, scope.Container); return(new CreatedSendScopeContext <Scope, T>(scope, sendContext)); } catch { scope.Dispose(); throw; } }