public IExecuteActivityScopeContext <TActivity, TArguments> GetScope(ExecuteContext <TArguments> context) { if (context.TryGetPayload <IUnityContainer>(out var existingContainer)) { var activity = existingContainer.Resolve <TActivity>(new DependencyOverride(typeof(TArguments), new InjectionParameter(context.Arguments))); ExecuteActivityContext <TActivity, TArguments> activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); return(new ExistingExecuteActivityScopeContext <TActivity, TArguments>(activityContext)); } var scope = _container.CreateChildContainer(); try { var activity = scope.Resolve <TActivity>(new DependencyOverride(typeof(TArguments), new InjectionParameter(context.Arguments))); ExecuteActivityContext <TActivity, TArguments> activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); var contextScope = scope; activityContext.GetOrAddPayload(() => contextScope); return(new CreatedExecuteActivityScopeContext <IUnityContainer, TActivity, TArguments>(contextScope, activityContext)); } catch { scope.Dispose(); throw; } }
public IExecuteActivityScopeContext <TActivity, TArguments> GetScope(ExecuteContext <TArguments> context) { if (context.TryGetPayload <ILifetimeScope>(out var existingLifetimeScope)) { var activity = existingLifetimeScope.Resolve <TActivity>(TypedParameter.From(context.Arguments)); ExecuteActivityContext <TActivity, TArguments> activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); return(new ExistingExecuteActivityScopeContext <TActivity, TArguments>(activityContext)); } var parentLifetimeScope = _scopeProvider.GetLifetimeScope(context.ConsumeContext); var lifetimeScope = parentLifetimeScope.BeginLifetimeScope(_name, builder => builder.ConfigureScope(context.ConsumeContext)); try { var activity = lifetimeScope.Resolve <TActivity>(TypedParameter.From(context.Arguments)); ExecuteActivityContext <TActivity, TArguments> activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); var scope = lifetimeScope; activityContext.GetOrAddPayload(() => scope); return(new CreatedExecuteActivityScopeContext <ILifetimeScope, TActivity, TArguments>(scope, activityContext)); } catch { lifetimeScope.Dispose(); throw; } }
public IExecuteActivityScopeContext <TActivity, TArguments> GetScope(ExecuteContext <TArguments> context) { if (context.TryGetPayload <IKernel>(out var kernel)) { kernel.UpdateScope(context.ConsumeContext); var activity = kernel.Resolve <TActivity>(new Arguments().AddTyped(context.Arguments)); ExecuteActivityContext <TActivity, TArguments> activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); return(new ExistingExecuteActivityScopeContext <TActivity, TArguments>(activityContext, ReleaseComponent)); } var scope = _kernel.CreateNewOrUseExistingMessageScope(context.ConsumeContext); try { var activity = _kernel.Resolve <TActivity>(new Arguments().AddTyped(context.Arguments)); ExecuteActivityContext <TActivity, TArguments> activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); activityContext.UpdatePayload(_kernel); return(new CreatedExecuteActivityScopeContext <IDisposable, TActivity, TArguments>(scope, activityContext, ReleaseComponent)); } catch { scope.Dispose(); throw; } }
public IExecuteActivityScopeContext <TActivity, TArguments> GetScope(ExecuteContext <TArguments> context) { if (context.TryGetPayload <IContainer>(out var existingContainer)) { existingContainer.Inject(context.ConsumeContext); var activity = existingContainer .With(context.Arguments) .GetInstance <TActivity>(); ExecuteActivityContext <TActivity, TArguments> activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); return(new ExistingExecuteActivityScopeContext <TActivity, TArguments>(activityContext)); } var nestedContainer = _container?.CreateNestedContainer(context.ConsumeContext) ?? _context?.CreateNestedContainer(context.ConsumeContext); try { var activity = nestedContainer .With(context.Arguments) .GetInstance <TActivity>(); ExecuteActivityContext <TActivity, TArguments> activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); activityContext.UpdatePayload(nestedContainer); return(new CreatedExecuteActivityScopeContext <IContainer, TActivity, TArguments>(nestedContainer, activityContext)); } catch { nestedContainer.Dispose(); throw; } }
public IExecuteActivityScopeContext <TActivity, TArguments> GetScope(ExecuteContext <TArguments> context) { if (context.TryGetPayload <IServiceProvider>(out var existingContainer)) { var activity = existingContainer.GetRequiredService <TActivity>(); ExecuteActivityContext <TActivity, TArguments> activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); return(new ExistingExecuteActivityScopeContext <TActivity, TArguments>(activityContext)); } var serviceScope = _serviceProvider.CreateScope(); try { var activity = serviceScope.ServiceProvider.GetRequiredService <TActivity>(); ExecuteActivityContext <TActivity, TArguments> activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); var scope = serviceScope; activityContext.GetOrAddPayload(() => scope); activityContext.GetOrAddPayload(() => scope.ServiceProvider); return(new CreatedExecuteActivityScopeContext <IServiceScope, TActivity, TArguments>(scope, activityContext)); } catch { serviceScope.Dispose(); throw; } }
public IExecuteActivityScopeContext <TActivity, TArguments> GetScope(ExecuteContext <TArguments> context) { if (context.TryGetPayload <INestedContainer>(out var existingContainer)) { var activityFactory = existingContainer.GetInstance <LamarActivityFactory>(); var activity = activityFactory.Get <TActivity, TArguments>(context.Arguments); var activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); return(new ExistingExecuteActivityScopeContext <TActivity, TArguments>(activityContext)); } var scopeContainer = _container.GetNestedContainer(context.ConsumeContext); try { var activityFactory = scopeContainer.GetInstance <LamarActivityFactory>(); var activity = activityFactory.Get <TActivity, TArguments>(context.Arguments); ExecuteActivityContext <TActivity, TArguments> activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); var scope = scopeContainer; activityContext.GetOrAddPayload(() => scope); return(new CreatedExecuteActivityScopeContext <INestedContainer, TActivity, TArguments>(scope, activityContext)); } catch { scopeContainer.Dispose(); throw; } }
public IExecuteActivityScopeContext <TActivity, TArguments> GetScope(ExecuteContext <TArguments> context) { if (context.TryGetPayload <Scope>(out var existingContainer)) { var activity = existingContainer .Container .GetInstance <TActivity>(); ExecuteActivityContext <TActivity, TArguments> activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); return(new ExistingExecuteActivityScopeContext <TActivity, TArguments>(activityContext)); } var scope = AsyncScopedLifestyle.BeginScope(_container); try { var activity = scope .Container .GetInstance <TActivity>(); ExecuteActivityContext <TActivity, TArguments> activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); var contextScope = scope; activityContext.GetOrAddPayload(() => contextScope); return(new CreatedExecuteActivityScopeContext <Scope, TActivity, TArguments>(contextScope, activityContext)); } catch { scope.Dispose(); throw; } }
public async Task Execute(ExecuteContext <TArguments> context, IPipe <ExecuteActivityContext <TArguments> > next) { using (var scope = _lifetimeScope.BeginLifetimeScope(x => ConfigureScope(x, context))) { if (_log.IsDebugEnabled) { _log.DebugFormat("ExecuteActivityFactory: Executing: {0}", TypeMetadataCache <TActivity> .ShortName); } var activity = scope.Resolve <TActivity>(TypedParameter.From(context.Arguments)); var activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); await next.Send(activityContext).ConfigureAwait(false); } }
public IExecuteActivityScopeContext <TActivity, TArguments> GetScope(ExecuteContext <TArguments> context) { if (context.TryGetPayload <IServiceScope>(out var existingServiceScope)) { existingServiceScope.UpdateScope(context.ConsumeContext); var activity = existingServiceScope.ServiceProvider.GetService <TActivity>(); if (activity == null) { throw new ConsumerException($"Unable to resolve activity type '{TypeMetadataCache<TActivity>.ShortName}'."); } ExecuteActivityContext <TActivity, TArguments> activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); return(new ExistingExecuteActivityScopeContext <TActivity, TArguments>(activityContext)); } if (!context.TryGetPayload(out IServiceProvider serviceProvider)) { serviceProvider = _serviceProvider; } var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope(); try { serviceScope.UpdateScope(context.ConsumeContext); var activity = serviceScope.ServiceProvider.GetService <TActivity>(); if (activity == null) { throw new ConsumerException($"Unable to resolve activity type '{TypeMetadataCache<TActivity>.ShortName}'."); } ExecuteActivityContext <TActivity, TArguments> activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); activityContext.UpdatePayload(serviceScope); return(new CreatedExecuteActivityScopeContext <IServiceScope, TActivity, TArguments>(serviceScope, activityContext)); } catch { serviceScope.Dispose(); throw; } }
public async Task Execute(ExecuteContext <TArguments> context, IPipe <ExecuteActivityContext <TActivity, TArguments> > next) { TActivity activity = null; try { activity = _executeFactory(context.Arguments); var activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); await next.Send(activityContext).ConfigureAwait(false); } finally { var disposable = activity as IDisposable; disposable?.Dispose(); } }
public async Task <ResultContext <ExecutionResult> > Execute(ExecuteContext <TArguments> context, IRequestPipe <ExecuteActivityContext <TActivity, TArguments>, ExecutionResult> next) { TActivity activity = null; try { activity = _executeFactory(context.Arguments); var activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); return(await next.Send(activityContext).ConfigureAwait(false)); } finally { var disposable = activity as IDisposable; disposable?.Dispose(); } }
public async Task Execute(ExecuteContext <TArguments> context, IPipe <ExecuteActivityContext <TArguments> > next) { using (_kernel.RequireScope()) { if (_log.IsDebugEnabled) { _log.DebugFormat("ExecuteActivityFactory: Executing: {0}", TypeMetadataCache <TActivity> .ShortName); } var activity = _kernel.Resolve <TActivity>(new { context.Arguments, context.ConsumeContext }); if (activity == null) { throw new ConsumerException($"Unable to resolve activity type '{TypeMetadataCache<TActivity>.ShortName}'."); } var activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); await next.Send(activityContext).ConfigureAwait(false); } }
public async Task <ResultContext <ExecutionResult> > Execute(ExecuteContext <TArguments> context, IRequestPipe <ExecuteActivityContext <TActivity, TArguments>, ExecutionResult> next) { using (var scope = _lifetimeScope.BeginLifetimeScope(x => ConfigureScope(x, context))) { if (_log.IsDebugEnabled) { _log.DebugFormat("ExecuteActivityFactory: Executing: {0}", TypeMetadataCache <TActivity> .ShortName); } var activity = scope.Resolve <TActivity>(TypedParameter.From(context.Arguments)); ExecuteActivityContext <TActivity, TArguments> activityContext = new HostExecuteActivityContext <TActivity, TArguments>(activity, context); var consumerLifetimeScope = scope; activityContext.GetOrAddPayload(() => consumerLifetimeScope); return(await next.Send(activityContext).ConfigureAwait(false)); } }