public void RunCommandWithPipeline()
        {
            var piplinesService = new DefaultMessagePipelineService();

            piplinesService.ServiceProvider = new FuncServiceProvider(InterfacesResolver);
            piplinesService.PipelineContainer.AddCommandPipeline()
            .AddMiddleware(new Commands.PipelineMiddlewares.CommandHandlerLocatorMiddleware(
                               typeof(CreateUserCommand).GetTypeInfo().Assembly))
            .AddMiddleware(new Commands.PipelineMiddlewares.CommandHandlerResolverMiddleware())
            .AddMiddleware(new Commands.PipelineMiddlewares.CommandHandlerExecutorMiddleware
            {
                UseParametersResolve = true
            });

            for (int i = 0; i < NumberOfInterations; i++)
            {
                var cmd = new CreateUserCommand
                {
                    FirstName = "Ivan",
                    LastName  = "Ivanov",
                    BirthDay  = new DateTime(1985, 1, 1),
                };
                piplinesService.HandleCommand(cmd);
            }
        }
        public decimal RunQueryWithPipeline()
        {
            var pipelineService = new DefaultMessagePipelineService();

            pipelineService.PipelineContainer.AddQueryPipeline()
            .AddMiddleware(new Queries.PipelineMiddlewares.QueryObjectResolverMiddleware
            {
                UseInternalObjectResolver = true
            })
            .AddMiddleware(new Queries.PipelineMiddlewares.QueryExecutorMiddleware());
            decimal result = 0;

            for (int i = 0; i < NumberOfInterations; i++)
            {
                result += pipelineService.Query <MathQueryHandlers>().With(q => q.Sum(2, 3));
            }
            return(result);
        }
Beispiel #3
0
        private static void Test()
        {
            var pipelineService = new DefaultMessagePipelineService();

            pipelineService.ServiceProvider   = new FuncServiceProvider(Resolver);
            pipelineService.PipelineContainer = new DefaultMessagePipelineContainer
            {
                Pipelines = new IMessagePipeline[]
                {
                    CommandPipeline,
                    QueryPipeline,
                    EventPipeline
                }
            };

            // Command.
            pipelineService.HandleCommand(new UpdateProductCommand
            {
                ProductId = 10,
                Name      = "Test",
            });
            Console.WriteLine(inMemoryMessageRepository.Dump());
            inMemoryMessageRepository.Messages.Clear();

            // Query.
            var list = pipelineService.Query <ProductsQueries>().With(q => q.Get(0, 10));

            Console.WriteLine(inMemoryMessageRepository.Dump());
            inMemoryMessageRepository.Messages.Clear();

            // Event.
            pipelineService.RaiseEvent(new UpdateProductEvent {
                Id = 1
            });
            Console.WriteLine(inMemoryMessageRepository.Dump());
            inMemoryMessageRepository.Messages.Clear();
        }
        private void ProcessMessage(MessageRecord messageRecord)
        {
            InternalLogger.Trace(string.Format(Properties.Strings.WebEndpoint_ProcessingMessage, messageRecord.Id,
                                               messageRecord.ContentType), nameof(WebEndpoint));
            var isPipelineFound = false;

            foreach (IMessagePipeline pipeline in pipelines)
            {
                if (pipeline.MessageTypes.Contains(messageRecord.Type))
                {
                    var converter = pipeline as IMessageRecordConverter;
                    if (converter != null)
                    {
                        var pipelineService = new DefaultMessagePipelineService();
                        pipelineService.ServiceProvider = serviceProviderFactory.Create();
                        var message = converter.CreateMessageContext(pipelineService, messageRecord);
                        try
                        {
                            pipeline.Invoke(message);
                        }
                        finally
                        {
                            var disposable = pipelineService.ServiceProvider as IDisposable;
                            disposable?.Dispose();
                        }
                    }
                    isPipelineFound = true;
                }
            }

            if (!isPipelineFound)
            {
                InternalLogger.Warn(string.Format(Properties.Strings.WebEndpoint_PipelineNotFound,
                                                  messageRecord.Type, messageRecord.Id, messageRecord.ContentType), nameof(WebEndpoint));
            }
        }