public void Release(IHandleRequests handler)
            {
                var disposable = handler as IDisposable;
                disposable?.Dispose();

                s_released += "|" + handler.Name;
            }
コード例 #2
0
ファイル: LifetimeScope.cs プロジェクト: iancooper/Paramore
 public void Add(IHandleRequests instance)
 {
     if (_handlerFactory == null)
         throw new ArgumentException("An instance of a handler can not be added without a HandlerFactory.");
     _trackedObjects.Add(instance);
     _logger.Value.DebugFormat("Tracking instance {0} of type {1}", instance.GetHashCode(), instance.GetType());
 }
コード例 #3
0
 /// <summary>
 /// Releases the specified handler.
 /// </summary>
 /// <param name="handler">The handler.</param>
 public void Release(IHandleRequests handler)
 {
     var disposable = handler as IDisposable;
     if (disposable != null)
     {
         disposable.Dispose();
     }
 }
コード例 #4
0
        public void Release(IHandleRequests handler)
        {
            var disposable = handler as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }
            handler = null;
        }
コード例 #5
0
        private void AppendToChain(IEnumerable <RequestHandlerAttribute> attributes, IHandleRequests <TRequest> implicitHandler, IRequestContext requestContext)
        {
            IHandleRequests <TRequest> lastInChain = implicitHandler;

            foreach (var attribute in attributes)
            {
                var decorator = new HandlerFactory <TRequest>(attribute, container, requestContext).CreateRequestHandler();
                lastInChain.Successor = decorator;
                lastInChain           = decorator;
            }
        }
コード例 #6
0
        void AppendToPipeline(IEnumerable <RequestHandlerAttribute> attributes, IHandleRequests <TRequest> implicitHandler, IRequestContext requestContext)
        {
            var lastInPipeline = implicitHandler;

            attributes.Each((attribute) =>
            {
                var decorator            = new HandlerFactory <TRequest>(attribute, handlerFactory, requestContext).CreateRequestHandler();
                lastInPipeline.Successor = decorator;
                lastInPipeline           = decorator;
            });
        }
コード例 #7
0
            public void Release(IHandleRequests handler)
            {
                var disposable = handler as IDisposable;

                if (disposable != null)
                {
                    disposable.Dispose();
                }

                s_released += "|" + handler.Name;
            }
コード例 #8
0
        /// <summary>
        /// Release the request handler - actual behavior depends on lifetime, we only dispose if we are transient
        /// </summary>
        /// <param name="handler"></param>
        public void Release(IHandleRequests handler)
        {
            if (!_isTransient)
            {
                return;
            }

            var disposal = handler as IDisposable;

            disposal?.Dispose();
        }
コード例 #9
0
 public void Add(IHandleRequests instance)
 {
     if (_handlerFactory == null)
     {
         throw new ArgumentException("An instance of a handler can not be added without a HandlerFactory.");
     }
     _trackedObjects.Add(instance);
     if (_logger != null)
     {
         _logger.DebugFormat("Tracking instance {0} of type {1}", instance.GetHashCode(), instance.GetType());
     }
 }
コード例 #10
0
        public void Setup()
        {
            var logger = new Mock <ILog>().Object;

            var registry = new SubscriberRegistry();

            registry.Register <TestCommand, TestCommandHandler>();
            var handlerFactory = new TestHandlerFactory <TestCommand, TestCommandHandler>(() => new TestCommandHandler(logger));

            pipelineBuilder = new PipelineBuilder <TestCommand>(registry, handlerFactory, logger);

            pipeline = pipelineBuilder.Build(new RequestContext()).First();
        }
コード例 #11
0
        public IHandleRequests Create(Type handlerType)
        {
            IServiceScope    scope          = _serviceProvider.CreateScope();
            IServiceProvider scopedProvider = scope.ServiceProvider;
            IHandleRequests  result         = (IHandleRequests)scopedProvider.GetService(handlerType);

            if (_activeHandlers.TryAdd(result, scope))
            {
                return(result);
            }

            scope.Dispose();
            throw new InvalidOperationException("The handler could not be tracked properly. It may be declared in the service collection with the wrong lifecyle.");
        }
        public void Setup()
        {
            var logger = new Mock <ILog>().Object;

            var registry = new SubscriberRegistry();

            registry.Register <TestCommand, TestImplicitHandler>();

            var container      = new TinyIoCContainer();
            var handlerFactory = new TinyIoCHandlerFactory(container);

            container.Register <IHandleRequests <TestCommand>, TestImplicitHandler>();
            container.Register <IHandleRequests <TestCommand>, TestLoggingHandler <TestCommand> >();
            container.Register(logger);

            pipelineBuilder = new PipelineBuilder <TestCommand>(registry, handlerFactory, logger);

            pipeline = pipelineBuilder.Build(new RequestContext()).First();
        }
コード例 #13
0
        private void AppendToPipeline(IEnumerable <RequestHandlerAttribute> attributes, IHandleRequests <TRequest> implicitHandler, IRequestContext requestContext)
        {
            IHandleRequests <TRequest> lastInPipeline = implicitHandler;

            attributes.Each(attribute =>
            {
                var handlerType = attribute.GetHandlerType();
                if (handlerType.GetTypeInfo().GetInterfaces().Contains(typeof(IHandleRequests)))
                {
                    var decorator =
                        new HandlerFactory <TRequest>(attribute, _handlerFactory, requestContext).CreateRequestHandler();
                    lastInPipeline.SetSuccessor(decorator);
                    lastInPipeline = decorator;
                }
                else
                {
                    var message = string.Format("All handlers in a pipeline must derive from IHandleRequests. You cannot have a mixed pipeline by including handler {0}", handlerType.Name);
                    throw new ConfigurationException(message);
                }
            });
        }
コード例 #14
0
        public void When_Building_A_Pipeline_Preserve_The_Order()
        {
            _pipeline = _pipelineBuilder.Build(new RequestContext()).First();

            PipelineTracer().ToString().Should().Be("MyLoggingHandler`1|MyValidationHandler`1|MyDoubleDecoratedHandler|");
        }
 public void Release(IHandleRequests handler)
 {
     var disposable = handler as IDisposable;
     disposable?.Dispose();
 }
コード例 #16
0
ファイル: LifetimeScope.cs プロジェクト: 40a/Paramore
 public void Add(IHandleRequests instance)
 {
     _trackedObjects.Add(instance);
     if (_logger != null)
         _logger.DebugFormat("Tracking instance {0} of type {1}", instance.GetHashCode(), instance.GetType());
 }
コード例 #17
0
 public void Add(IHandleRequests <TRequest> handler)
 {
     chains.Add(handler);
 }
コード例 #18
0
 public void Release(IHandleRequests handler)
 {
     // nothing to do
 }
コード例 #19
0
 /// <summary>
 /// Sets the successor.
 /// </summary>
 /// <param name="successor">The successor.</param>
 public void SetSuccessor(IHandleRequests <TRequest> successor)
 {
     _successor = successor;
 }
 public void Release(IHandleRequests handler) {}
        public void When_Building_A_Pipeline_Allow_Pre_And_Post_Tasks()
        {
            _pipeline = _pipelineBuilder.Build(new RequestContext()).First();

            TraceFilters().ToString().Should().Be("MyValidationHandler`1|MyPreAndPostDecoratedHandler|MyLoggingHandler`1|");
        }
コード例 #22
0
        public void Release(IHandleRequests handler)
        {
            var disposable = handler as IDisposable;

            disposable?.Dispose();
        }
コード例 #23
0
 public CommentsController(IHandleRequests handler, IMongoStore mongo)
 {
     _handler = handler;
     _mongo   = mongo;
 }
コード例 #24
0
        IHandleRequests <TRequest> PushOntoPipeline(IEnumerable <RequestHandlerAttribute> attributes, IHandleRequests <TRequest> lastInPipeline, IRequestContext requestContext)
        {
            attributes.Each((attribute) =>
            {
                var decorator       = new HandlerFactory <TRequest>(attribute, handlerFactory, requestContext).CreateRequestHandler();
                decorator.Successor = lastInPipeline;
                lastInPipeline      = decorator;
            });

            return(lastInPipeline);
        }
コード例 #25
0
 private IHandleRequests <TRequest> PushOntoChain(IEnumerable <RequestHandlerAttribute> attributes, IHandleRequests <TRequest> lastInChain, IRequestContext requestContext)
 {
     foreach (var attribute in attributes)
     {
         var decorator = new HandlerFactory <TRequest>(attribute, container, requestContext).CreateRequestHandler();
         decorator.Successor = lastInChain;
         lastInChain         = decorator;
     }
     return(lastInChain);
 }
コード例 #26
0
 public void Release(IHandleRequests handler)
 {
 }
コード例 #27
0
 public PostRequestDecorator(IHandleRequests <TRequest, TResponse> inner) : base(inner)
 {
 }
コード例 #28
0
ファイル: Pipelines.cs プロジェクト: danbarua/Paramore
 public void Add(IHandleRequests <TRequest> handler)
 {
     filters.Add(handler);
 }
コード例 #29
0
 public MaternityBenefitsBulkRequestHandler(
     IHandleRequests <MaternityBenefitsRequest, MaternityBenefitsResponse> requestHandler
     )
 {
     _requestHandler = requestHandler;
 }
コード例 #30
0
        public void When_Building_A_Pipeline_Allow_ForeignAttributes()
        {
            _pipeline = _pipelineBuilder.Build(new RequestContext()).First();

            TraceFilters().ToString().Should().Be("MyValidationHandler`1|MyObsoleteCommandHandler|MyLoggingHandler`1|");
        }
        public void When_Building_A_Pipeline_Allow_ForiegnAttribues()
        {
            _pipeline = _pipelineBuilder.Build(new RequestContext()).First();

            Assert.AreEqual("MyValidationHandler`1|MyObsoleteCommandHandler|MyLoggingHandler`1|", TraceFilters().ToString());
        }