public ISagaQueryScopeContext <TSaga, T> GetQueryScope <T>(SagaQueryConsumeContext <TSaga, T> context) where T : class { if (context.TryGetPayload <IKernel>(out _)) { return(new ExistingSagaQueryScopeContext <TSaga, T>(context)); } var scope = _container.BeginScope(); _container.Register(Component.For <ConsumeContext, ConsumeContext <T> >().Instance(context)); try { var proxy = new SagaQueryConsumeContextProxy <TSaga, T>(context, new PayloadCacheScope(context), context.Query); var consumerContainer = _container; proxy.GetOrAddPayload(() => consumerContainer); foreach (Action <ConsumeContext> scopeAction in _scopeActions) { scopeAction(proxy); } return(new CreatedSagaQueryScopeContext <IDisposable, TSaga, T>(scope, proxy)); } catch { scope.Dispose(); throw; } }
public Task <TResponse> Send <TResponse>(IRequest <TResponse> request, CancellationToken cancellationToken = new CancellationToken()) { using (_kernel.BeginScope()) { return(_mediator.Send(request, cancellationToken)); } }
public async Task Send <T>(ConsumeContext <T> context, ISagaPolicy <TSaga, T> policy, IPipe <SagaConsumeContext <TSaga, T> > next) where T : class { using (_container.BeginScope()) { await _repository.Send(context, policy, next); } }
private void BeginScopedLifestyleIfRequired() { if (autoCreateLifestyleScopes) { HttpContext.Current.Items[ContextScopeKey] = kernel.BeginScope(); } }
/// <summary>Intercepts the specified invocation.</summary> /// <param name="invocation">The invocation.</param> public void Intercept(IInvocation invocation) { using (_kernel.BeginScope()) { invocation.Proceed(); } }
public static IDisposable CreateNewMessageScope <T>(this IKernel kernel, PublishContext <T> publishContext) where T : class { var beginScope = kernel.BeginScope(); return(beginScope); }
public WindsorDependencyScope(IKernel container) { if (container == null) { throw new ArgumentNullException("container"); } _container = container; _scope = container.BeginScope(); }
public async Task <T> Execute <T>(Func <SagaRepositoryContext <TSaga>, Task <T> > asyncMethod, CancellationToken cancellationToken) where T : class { using var scope = _kernel.BeginScope(); var factory = _kernel.Resolve <ISagaRepositoryContextFactory <TSaga> >(); return(await factory.Execute(asyncMethod, cancellationToken).ConfigureAwait(false)); }
public static IDisposable RequireScope(this IKernel kernel) { var current = Scope.ObtainCurrentScope(); if (current == null) { return(kernel.BeginScope()); } return(null); }
public static IDisposable CreateNewOrUseExistingMessageScope(this IKernel kernel) { var currentScope = CallContextLifetimeScope.ObtainCurrentScope(); if (currentScope is MessageLifetimeScope) { return(null); } return(kernel.BeginScope()); }
public static IDisposable CreateNewOrUseExistingMessageScope(this IKernel kernel) { var currentScope = CallContextLifetimeScope.ObtainCurrentScope(); if (currentScope is MessageLifetimeScope scope) { kernel.Resolve <ScopedConsumeContextProvider>().SetContext(scope.ConsumeContext); return(null); } return(kernel.BeginScope()); }
/// <summary> /// Called by MVC system and creates controller instance for given controller type. /// </summary> /// <param name="requestContext">Request context</param> /// <param name="controllerType">Controller type</param> /// <returns></returns> protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) { if (controllerType == null) { throw new HttpException(404, string.Format("The controller for path '{0}' could not be found.", requestContext.HttpContext.Request.Path)); } //开启单次请求周期作用域范围 using (var scope = _kernel.BeginScope()) { return((IController)_kernel.Resolve(controllerType)); } }
/// <summary> /// Retrieves the controller instance for the specified request context and controller type. /// </summary> /// <param name="requestContext">The context of the HTTP request, which includes the HTTP context and route data.</param> /// <param name="controllerType">The type of the controller.</param> /// <returns> /// The controller instance. /// </returns> /// <exception cref="System.Web.HttpException">Error 40.4</exception> protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) { if (controllerType == null) { throw new HttpException(404, string.Format(CultureInfo.InvariantCulture, "The controller for path '{0}' could not be found.", requestContext.HttpContext.Request.Path)); } using (kernel.BeginScope()) { return((IController)this.kernel.Resolve(controllerType)); } }
public CustomDependencyScope(IKernel kernel, IDependencyResolver currentResolver) { if (kernel == null) { throw new ArgumentNullException(nameof(kernel)); } if (currentResolver == null) { throw new ArgumentNullException(nameof(currentResolver)); } _kernel = kernel; _windsorScope = kernel.BeginScope(); _currentResolverScope = currentResolver.BeginScope(); }
public async Task Send <TMessage>(ConsumeContext <TMessage> context, IPipe <ConsumerConsumeContext <TConsumer, TMessage> > next) where TMessage : class { using (_container.BeginScope()) { var consumer = _container.Resolve <TConsumer>(); if (consumer == null) { throw new ConsumerException(string.Format("Unable to resolve consumer type '{0}'.", TypeMetadataCache <TConsumer> .ShortName)); } try { await next.Send(context.PushConsumer(consumer)); } finally { _container.ReleaseComponent(consumer); } } }
public async Task <TResponse> ExecuteAsync <TRequest, TResponse>(TRequest request) where TRequest : class where TResponse : class { var requestType = typeof(TRequest).FullName.Replace("Cookbook.Contracts.Requests.", ""); var stopwatch = new Stopwatch(); IHandler <TRequest, TResponse> handler = null; using (_container.BeginScope()) { try { stopwatch.Start(); handler = _handlerFactory.Resolve <TRequest, TResponse>(); var returnValue = await handler.HandleAsync(request); stopwatch.Stop(); Log.InfoFormat(InfoMessage, requestType, stopwatch.ElapsedMilliseconds); return(returnValue); } catch (Common.ApiException orbisEx) { Log.WarnFormat(orbisEx, WarnMessage, requestType, stopwatch.ElapsedMilliseconds); throw; } catch (Exception ex) { Log.ErrorFormat(ex, WarnMessage, requestType, stopwatch.ElapsedMilliseconds); throw; } finally { if (handler != null) { _handlerFactory.Release(handler); } } } }
public void ProcessModel(IKernel kernel, ComponentModel model) { if (model.Configuration.Attributes.Get(AspNetCoreFacility.IsRegisteredAsMiddlewareIntoApplicationBuilderKey) == Boolean.TrueString) { foreach (var service in model.Services) { applicationBuilder.Use(async(context, next) => { var windsorScope = kernel.BeginScope(); var serviceProviderScope = (provider = provider ?? services.BuildServiceProvider()).CreateScope(); try { var middleware = (IMiddleware)kernel.Resolve(service); await middleware.InvokeAsync(context, async(ctx) => await next()); } finally { serviceProviderScope.Dispose(); windsorScope.Dispose(); } }); } } }
public DependencyScope(IKernel kernel) { this.kernel = kernel; disposable = kernel.BeginScope(); }
public WindsorWebApiDependencyScope(IKernel container) { _container = container; _scope = container.BeginScope(); }
public WindsorDependencyScope(IKernel kernel) { _kernel = kernel; _disposable = kernel.BeginScope(); }
public WindsorDependencyResolverScope(IKernel kernel) { _kernel = kernel; _scope = _kernel.BeginScope(); }
private WindsorJobActivatorScope CreateScope() { // support scoped lifestyles (https://github.com/castleproject/Windsor/blob/master/docs/lifestyles.md#scoped) return(new WindsorJobActivatorScope(this, _kernel.BeginScope())); }
public WindsorDependencyScope(IKernel container) { this.container = container; this.scope = container.BeginScope(); }
public WindsorDependencyScope(IKernel container) { _container = container; _scope = container.BeginScope(); }
public DependencyScope(IKernel kernel) { _kernel = kernel; _disposable = kernel.BeginScope(); }
public CastleDependencyScope(IKernel kernel) { this._kernel = kernel; disposable = _kernel.BeginScope(); }
public WindsorDependencyScope(IKernel kernel) { this._kernel = kernel; this._scope = kernel.BeginScope(); }
public IScope BeginScope() { var scope = _kernel.BeginScope(); return(new WindsorScope(_kernel, scope)); }
public AspNetWebApiDependencyScope(AspNetWebApiDependencyResolver parentResolver, IKernel kernel) { this.parentResolver = parentResolver; this.kernel = kernel; this.scope = kernel.BeginScope(); }
public WindsorDependencyScope(IKernel kernel) { this._kernel = kernel; _disposable = kernel.BeginScope(); }
public WindsorDependencyScope(IKernel kernel) { Kernel = kernel; _scope = kernel.BeginScope(); }
protected internal IDisposable StartScope() { return(_kernel.BeginScope()); }