Exemple #1
0
        private static async Task MainAsync()
        {
            var containerBuilder = new ContainerBuilder();

            ConfigurationConfigurator.RegisterConfigurationSettings()
            .FromAssemblies(typeof(Program).Assembly)
            .RegisterWithContainer(configSetting => containerBuilder.RegisterInstance(configSetting)
                                   .AsSelf()
                                   .SingleInstance())
            .DoYourThing();
            containerBuilder.RegisterType <BusConfiguration>().SingleInstance().AsImplementedInterfaces();
            containerBuilder.Register(container =>
            {
                var busConfig       = container.Resolve <IBusConfiguration>();
                var mediatorBuilder = new MediatorBuilder();
                return(mediatorBuilder.RegisterHandlers(typeof(Program).Assembly)
                       .ConfigurePublishPipe(x =>
                {
                    x.UseMessageQueue(() => busConfig,
                                      () => true);
                }).Build());
            }).AsImplementedInterfaces();


            using (var container = containerBuilder.Build())
            {
                var mediator = container.Resolve <IMediator>();
                await mediator.SendAsync(new CalculateTotalCommand(1, 2));
            }
        }
        void GivenAMediator()
        {
            ClearBinding();
            var builder = new MediatorBuilder();

            _mediator = builder.RegisterHandlers(() =>
            {
                var binding = new List <MessageBinding>()
                {
                    new MessageBinding(typeof(TestBaseCommand), typeof(TestBaseCommandHandlerRaiseEvent)),
                    new MessageBinding(typeof(TestEvent), typeof(TestEventHandler))
                };
                return(binding);
            })
                        .ConfigureGlobalReceivePipe(x =>
            {
                x.UseConsoleLogger1();
            })
                        .ConfigureCommandReceivePipe(x =>
            {
                x.UseConsoleLogger2();
            })
                        .ConfigurePublishPipe(x =>
            {
                x.UseConsoleLogger3();
            })
                        .Build();
        }
Exemple #3
0
        public void GivenAMediatorAndTwoMiddlewares()
        {
            ClearBinding();
            var builder = new MediatorBuilder();

            _mediator = builder.RegisterHandlers(() =>
            {
                var binding = new List <MessageBinding>()
                {
                    new MessageBinding(typeof(GetGuidRequest), typeof(GetGuidRequestHandler)),
                    new MessageBinding(typeof(GetGuidRequest), typeof(GetGuidRequestHandler2))
                };
                return(binding);
            })
                        .ConfigureCommandReceivePipe(x =>
            {
                x.UseConsoleLogger1();
                x.UseConsoleLogger2();
            })
                        .ConfigureRequestPipe(x =>
            {
                x.UseConsoleLogger3();
            })
                        .Build();
        }
        public void GivenAMediatorBuildConnectsToAllPipelines()
        {
            base.ClearBinding();
            var mediaBuilder = new MediatorBuilder();

            mediaBuilder.RegisterHandlers(TestUtilAssembly.Assembly)
            .ConfigureGlobalReceivePipe(global =>
            {
                global.UseSimpleMiddleware1();
            })
            .ConfigureCommandReceivePipe(x =>
            {
                x.UseSimpleMiddleware1();
            })
            .ConfigureEventReceivePipe(e =>
            {
                e.UseSimpleMiddleware1();
            })
            .ConfigurePublishPipe(p =>
            {
                p.UseSimpleMiddleware1();
            }).ConfigureRequestPipe(r =>
            {
                r.UseSimpleMiddleware1();
            });
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterType <SimpleService>().AsSelf();
            containerBuilder.RegisterType <AnotherSimpleService>().AsSelf();
            containerBuilder.RegisterMediator(mediaBuilder);
            _container = containerBuilder.Build();
        }
Exemple #5
0
 public static MediatorBuilder RegisterUnduplicatedHandlers(this MediatorBuilder mediatorBuilder)
 {
     return(mediatorBuilder.RegisterHandlers(
                assembly => assembly.DefinedTypes.Where(t => t.Name != nameof(MultiRequestsHandler) &&
                                                        t.Name != nameof(MultiEventsHandler) &&
                                                        t.Name != nameof(MultiCommandsHandler)),
                TestUtilAssembly.Assembly));
 }
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);
            var mediatorBuilder = new MediatorBuilder();

            mediatorBuilder.RegisterHandlers(this.GetType().Assembly);
            builder.RegisterMediator(mediatorBuilder);
        }
        private static IUnityContainer ConfigureContainer()
        {
            var container = new UnityContainer();

            var mediaBuilder = new MediatorBuilder();

            mediaBuilder.RegisterHandlers(typeof(MediatorNetUnit).Assembly);
            UnityExtensioins.Configure(mediaBuilder, container);

            return(container);
        }
        public void GivenAContainer()
        {
            var mediaBuilder = new MediatorBuilder();

            mediaBuilder.RegisterHandlers(TestUtilAssembly.Assembly)
            .ConfigureCommandReceivePipe(x =>
            {
                x.UseSimpleMiddleware();
            });
            _container = new Container();
            StructureMapExtensions.Configure(mediaBuilder, _container);
        }
        public void GivenAMediator()
        {
            var builder = new MediatorBuilder();

            _mediator = builder.RegisterHandlers(() =>
            {
                var binding = new List <MessageBinding> {
                    new MessageBinding(typeof(TestEvent), typeof(TestEventHandler))
                };
                return(binding);
            }).Build();
        }
Exemple #10
0
        void ConfigureMediator(IServiceCollection services)
        {
            services
            .AddTransient <SimpleService>()
            .AddTransient <AnotherSimpleService>()
            .AddTransient <ICalculateService, CalculateService>()
            .AddTransient <IBoardcastService, BoardcastService>();
            var mediatorBuilder = new MediatorBuilder();

            mediatorBuilder.RegisterHandlers(assembly => assembly.DefinedTypes.Where(t => t.Name != nameof(MultiRequestsHandler)), TestUtilAssembly.Assembly, typeof(Startup).Assembly);
            services.RegisterMediator(mediatorBuilder);
        }
 public void AndGivenABindingWithOneCommandMultipleHandlers()
 {
     _mediator = _builder.RegisterHandlers(() =>
     {
         var binding = new List <MessageBinding>()
         {
             new MessageBinding(typeof(TestBaseCommand), typeof(TestBaseCommandHandler)),
             new MessageBinding(typeof(TestBaseCommand), typeof(TestBaseCommandHandler)),
         };
         return(binding);
     }).Build();
 }
Exemple #12
0
        public void GivenAMediatorWithNoPipeline()
        {
            var builder = new MediatorBuilder();

            _mediator = builder.RegisterHandlers(() =>
            {
                var binding = new List <MessageBinding> {
                    new MessageBinding(typeof(TestBaseCommand), typeof(TestBaseCommandHandler))
                };
                return(binding);
            }).Build();
        }
        public void GivenAContainer()
        {
            var mediaBuilder = new MediatorBuilder();

            mediaBuilder.RegisterHandlers(TestUtilAssembly.Assembly)
            .ConfigureCommandReceivePipe(x =>
            {
                x.UseSimpleMiddleware();
            });
            _container = new Container();
            _container.Options.DefaultScopedLifestyle = new LifetimeScopeLifestyle();
            InjectHelper.RegisterMediator(_container, mediaBuilder);
        }
Exemple #14
0
        IMediator SetupCommandMediatorWithExplicitBindings()
        {
            var builder = new MediatorBuilder();

            return(builder.RegisterHandlers(() =>
            {
                var binding = new List <MessageBinding>
                {
                    new MessageBinding(typeof(AnotherCommand), typeof(MultiCommandsHandler)),
                    new MessageBinding(typeof(DerivedTestBaseCommand), typeof(MultiCommandsHandler))
                };
                return binding;
            }).Build());
        }
Exemple #15
0
        public void GivenAMediatorWithUnitOfWork()
        {
            var builder = new MediatorBuilder();

            builder.RegisterHandlers(typeof(ExceptionInHandlerShouldRollbackTransaction).Assembly)
            .ConfigureGlobalReceivePipe(x =>
            {
                x.UseUnitOfWork(() => true);
            });

            ContainerBuilder.RegisterMediator(builder);

            _container = ContainerBuilder.Build();
        }
        public void GivenAContainer()
        {
            var mediaBuilder = new MediatorBuilder();

            mediaBuilder.RegisterHandlers(TestUtilAssembly.Assembly)
            .ConfigureCommandReceivePipe(x =>
            {
                x.UseSimpleMiddleware();
            });
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterMediator(mediaBuilder);
            _container = containerBuilder.Build();
        }
Exemple #17
0
        IMediator SetupRequestMediatorWithExplicitBindings()
        {
            var builder = new MediatorBuilder();

            return(builder.RegisterHandlers(() =>
            {
                var binding = new List <MessageBinding>()
                {
                    new MessageBinding(typeof(GetGuidRequest), typeof(MultiRequestsHandler)),
                    new MessageBinding(typeof(SimpleRequest), typeof(MultiRequestsHandler))
                };
                return binding;
            }).Build());
        }
        void GivenAMediator()
        {
            var builder = new MediatorBuilder();

            _mediator = builder.RegisterHandlers(() =>
            {
                var binding = new List <MessageBinding>()
                {
                    new MessageBinding(typeof(TestBaseCommand), typeof(TestBaseCommandHandler)),
                    new MessageBinding(typeof(DerivedTestBaseCommand), typeof(DerivedTestBaseCommandHandler)),
                };
                return(binding);
            }).Build();
        }
        void GivenAMediator()
        {
            ClearBinding();
            var builder = new MediatorBuilder();

            _mediator = builder.RegisterHandlers(() =>
            {
                var binding = new List <MessageBinding> {
                    new MessageBinding(typeof(TestBaseCommand), typeof(SimpleCommandHandler))
                };
                return(binding);
            })
                        .Build();
        }
Exemple #20
0
        public void GivenAMediator()
        {
            var builder = new MediatorBuilder();

            _mediator = builder.RegisterHandlers(() =>
            {
                var binding = new List <MessageBinding>
                {
                    new MessageBinding(typeof(AnotherCommand), typeof(MultiCommandsHandler)),
                    new MessageBinding(typeof(DerivedTestBaseCommand), typeof(MultiCommandsHandler))
                };
                return(binding);
            }).Build();
        }
Exemple #21
0
        IMediator SetupEventMediatorWithExplicitBindings()
        {
            var builder = new MediatorBuilder();

            return(builder.RegisterHandlers(() =>
            {
                var binding = new List <MessageBinding>
                {
                    new MessageBinding(typeof(SimpleEvent), typeof(MultiEventsHandler)),
                    new MessageBinding(typeof(TestEvent), typeof(MultiEventsHandler))
                };
                return binding;
            }).Build());
        }
Exemple #22
0
        public void GivenAContainer()
        {
            var mediaBuilder = new MediatorBuilder();

            mediaBuilder.RegisterHandlers(TestUtilAssembly.Assembly)
            .ConfigureCommandReceivePipe(x =>
            {
                x.UseSimpleMiddleware();
            });
            _container = new UnityContainer();
            _container.RegisterType <SimpleService>();
            _container.RegisterType <AnotherSimpleService>();

            UnityExtensioins.Configure(mediaBuilder, _container);
        }
Exemple #23
0
        public void GivenAMediatorAndTwoMiddlewares()
        {
            var binding = new List <MessageBinding>()
            {
                new MessageBinding(typeof(TestBaseCommand), typeof(TestBaseCommandHandler))
            };
            var builder = new MediatorBuilder();

            _mediator = builder.RegisterHandlers(binding)
                        .ConfigureCommandReceivePipe(x =>
            {
                x.UseConsoleLogger1();
                x.UseConsoleLogger2();
            })
                        .Build();
        }
        void GivenAMediator()
        {
            ClearBinding();
            var builder = new MediatorBuilder();

            _mediator = builder.RegisterHandlers(() =>
            {
                var binding = new List <MessageBinding>
                {
                    new MessageBinding(typeof(TestEvent), typeof(TestEventHandler)),
                    new MessageBinding(typeof(TestEvent), typeof(MultiTestEventHandlerHandleTheSameEvent)),
                };
                return(binding);
            })
                        .Build();
        }
        public void GivenAContainer()
        {
            var mediaBuilder = new MediatorBuilder();

            mediaBuilder.RegisterHandlers(TestUtilAssembly.Assembly)
            .ConfigureRequestPipe(x =>
            {
                x.UseSimpleMiddleware();
            });
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterType <SimpleService>().AsSelf();
            containerBuilder.RegisterType <AnotherSimpleService>().AsSelf();
            containerBuilder.RegisterMediator(mediaBuilder);
            _container = containerBuilder.Build();
        }
Exemple #26
0
        public TestUseCustomReceiveContext()
        {
            ClearBinding();
            var builder = new MediatorBuilder();

            _mediator = builder.RegisterHandlers(() =>
            {
                var binding = new List <MessageBinding>
                {
                    new MessageBinding(typeof(TestBaseCommand), typeof(AsyncTestBaseCommandHandler)),
                    new MessageBinding(typeof(TestEvent), typeof(TestEventHandler)),
                    new MessageBinding(typeof(GetGuidRequest), typeof(GetGuidRequestHandler))
                };
                return(binding);
            })
                        .Build();
        }
        void GivenAContainer()
        {
            base.ClearBinding();
            var mediaBuilder = new MediatorBuilder();

            mediaBuilder.RegisterHandlers(TestUtilAssembly.Assembly)
            .ConfigureCommandReceivePipe(x =>
            {
                x.UseSimpleMiddleware();
            });
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterType <SimpleService>().AsSelf();
            containerBuilder.RegisterType <AnotherSimpleService>().AsSelf();
            containerBuilder.RegisterMediator(mediaBuilder);
            _container = containerBuilder.Build();
        }
        public void GivenAMediator()
        {
            var builder = new MediatorBuilder();

            _mediator = builder.RegisterHandlers(() =>
            {
                var binding = new List <MessageBinding> {
                    new MessageBinding(typeof(NoWorkCommand), typeof(NoWorkCommandHandler))
                };
                return(binding);
            })
                        .ConfigureGlobalReceivePipe(x =>
            {
                x.UseNoWorkMiddleware();
            })
                        .Build();
        }
        public async Task TestRequestHandler()
        {
            ClearBinding();
            var builder = new MediatorBuilder();

            _mediator = builder.RegisterHandlers(() =>
            {
                var binding = new List <MessageBinding> {
                    new MessageBinding(typeof(InheritanceRequest), typeof(ChildRequestHandler))
                };
                return(binding);
            }).Build();

            var response = await _mediator.RequestAsync <InheritanceRequest, InheritanceResponse>(new InheritanceRequest(_id));

            response.Id.ShouldBe(_id);
            response.Content.ShouldBe("Hello world");
        }
Exemple #30
0
        void GivenAContainer()
        {
            ClearBinding();
            var mediaBuilder = new MediatorBuilder();

            mediaBuilder.RegisterHandlers(TestUtilAssembly.Assembly)
            .ConfigureCommandReceivePipe(x =>
            {
                x.UseSimpleMiddleware();
            });
            _container = new Container();
            _container.Configure(x =>
            {
                x.ForConcreteType <SimpleService>();
                x.ForConcreteType <AnotherSimpleService>();
            });
            StructureMapExtensions.Configure(mediaBuilder, _container);
        }