public async Task CommandBus_Publishes_To_Multiple_Subscribers() { var bus = new CommandBus(); var source1 = new TaskCompletionSource<bool>(); var source2 = new TaskCompletionSource<bool>(); bus.Subscribe<SaveCommand>((cmd) => { var saveCommand = (SaveCommand)cmd; Assert.That(saveCommand.DeviceId, Is.EqualTo("1234")); source1.SetResult(true); }); bus.Subscribe<SaveCommand>((cmd) => { var saveCommand = (SaveCommand)cmd; Assert.That(saveCommand.DeviceId, Is.EqualTo("1234")); source2.SetResult(true); }); var command = new SaveCommand("1234"); await bus.Publish(command); await Task.WhenAll(source1.Task, source2.Task).ContinueWith((obj) => { bus.RemoveAllSubscriptions(); }); }
public void FunctionFor0HandleresDoesNotDoAnythig() { var commanBus = new CommandBus(); commanBus.RegisterHandlers<FuncCommand>("nonExistentNamespaceWillHave 0 handlers"); commanBus.Publish(new FuncCommand()); }
public MessageLogger( CommandBus commandBus, IAsyncQueryHandler<GetRoutesQuery, GetRoutesQueryResponse> getRoutesQueryHandler, IAsyncQueryHandler<GetRouteQuery, GetRouteQueryResponse> getRouteQueryHandler) { this.commandBus = commandBus; this.getRoutesQueryHandler = getRoutesQueryHandler; this.getRouteQueryHandler = getRouteQueryHandler; }
public void Setup() { command = new TestCommand(); commandHandler = Substitute.For<ICommandHandler<TestCommand>>(); commandHandlerResolver = Substitute.For<ICommandHandlerResolver>(); commandHandlerResolver.ResolveCommandHandler<ICommandHandler<TestCommand>>().Returns(commandHandler); sut = new CommandBus(commandHandlerResolver); }
public void FunctionCallsAHandlerAndReturns() { var commanBus = new CommandBus(); commanBus.RegisterHandlers<FuncCommand>("Commandos.Specs.Samples"); var command = new FuncCommand(); var result = commanBus.Publish<FuncCommand>((object) command); Assert.That(command, Is.SameAs(result)); }
public virtual void Setup() { Bus = MockRepository.GenerateStub<IBus>(); TestController = new TestController(); Container = MockRepository.GenerateStub<IContainer>(); TestCommandMessage = MockRepository.GenerateStub<ITestCommandMessage>(); Bus.Stub(bus => bus.CreateInstance<ITestCommandMessage>()).Return(TestCommandMessage); CommandBus = new CommandBus(Bus, Container); }
public RabbitMQSubscriber(CommandBus bus) { this.bus = bus; Console.WriteLine("Creating factory..."); factory = new ConnectionFactory(); Console.WriteLine("Creating connection..."); factory.Protocol = Protocols.FromEnvironment(); factory.HostName = "localhost"; conn = factory.CreateConnection(); }
public Infrastructure(CommandBus commandBus, IEventAggregator eventAggregator, IWindowManager windowManager, ElasticOpsConfig config) { CommandBus = commandBus; EventAggregator = eventAggregator; WindowManager = windowManager; Config = config; Connection = new Connection(); }
public void ActionCallsVoidHandler() { var commanBus = new CommandBus(); commanBus.RegisterHandlers<FuncCommand>("Commandos.Specs.Samples"); var command = new ActionCommand(); commanBus.Publish(command); Assert.IsTrue(command.Called); }
public void BuildOrder() { var commandBus = new CommandBus(); var orderCommand = new BuildOrder { OrderNo = "ON1001", OrderAmount = 10000, ProductNo = "PN1001", UserIdentifier = "UID1001" }; var result = commandBus.Excute(orderCommand); Assert.IsTrue(result.Result); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); var bus = new CommandBus(); var commands = new CommandHandlers(); bus.RegisterHandler<PostTransactionCommand>(commands.Handle); ServiceLocator.CommandBus = bus; var events = new EventHandlers(); DomainEvents.Register<AccountLockedEvent>(events.Handle); DomainEvents.Register<AccountOverdrawnEvent>(events.Handle); DomainEvents.Register<TransationPostedEvent>(events.Handle); }
public UnitTest2() { CommandResultReposiotry commandResultReposiotry = new CommandResultReposiotry(); CustomerRepository customerRepository = new CustomerRepository(); CustomerCommandHandler customerCommandHandler = new CustomerCommandHandler(customerRepository, commandResultReposiotry); CommandResultQueryaHandler commandResultQueryaHandler = new CommandResultQueryaHandler(commandResultReposiotry); CommandBus commandBus = new CommandBus(); commandBus.Registerd<CustomerCreateCommand>(customerCommandHandler); QueryBus queryBus = new QueryBus(); queryBus.Registerd<CommandResultQuery>(commandResultQueryaHandler); _commandBus = commandBus; _queryBus = queryBus; }
public static void Main(string[] args) { var commandBus = new CommandBus(); var sessionFactory = DbConfig(); var accountReportView = new AccountReportView(sessionFactory); commandBus.RegisterHandlerEvent<AccountCreatedEvent>(accountReportView.Handle); commandBus.RegisterHandlerEvent<AccountNameAndBalanceChangedEvent>(accountReportView.Handle); commandBus.RegisterHandlerEvent<BalanceDecreasedEvent>(accountReportView.Handle); commandBus.RegisterHandlerEvent<BalanceIncreasedEvent>(accountReportView.Handle); var r = new RunRabbitMQSubscriber(commandBus); }
public async Task CommandBus_Publishes_To_Single_Subscriber() { var bus = new CommandBus(); var source = new TaskCompletionSource<bool>(); bus.Subscribe<SaveCommand>((cmd) => { var saveCommand = (SaveCommand)cmd; Assert.That(saveCommand.DeviceId, Is.EqualTo("1234")); bus.RemoveAllSubscriptions(); source.SetResult(true); }); var command = new SaveCommand("1234"); await bus.Publish(command); await source.Task; }
public async Task CommandBus_Subscribes_With_Command_String() { var bus = new CommandBus(); var source = new TaskCompletionSource<bool>(); bus.Subscribe("SaveCommand", (cmd) => { var saveCommand = (SaveCommand)cmd; Assert.That(saveCommand.DeviceId, Is.EqualTo("1234")); bus.RemoveAllSubscriptions(); source.SetResult(true); return null; }); var command = new SaveCommand("1234"); await bus.Publish(command); await source.Task; }
internal TransportConfigurator RegisterDomainBuses(IContainer container) { var serviceBus = container.GetInstance<ServiceBus>(); var serviceProvider = container.GetInstance<IServiceProvider>(); var entityIdGenerator = container.GetInstance<IEntityIdGenerator>(); var validationRegistry = new FluentValidatorsRegistry(serviceProvider); validationRegistry.Register(typeof(Namespace_DomainProject).Assembly); var commandValidationFactory = new FluentCommandValidationFacade(validationRegistry); var commandBus = new CommandBus(serviceBus, EndpointAddress.Create("whowhat.input", Environment.MachineName), entityIdGenerator, commandValidationFactory); var eventBus = new EventBus(serviceBus, EndpointAddress.Create("whowhat.input", Environment.MachineName)); container.Configure(config => { config.For<CommandBus>().Singleton().Use(commandBus); config.For<EventBus>().Singleton().Use(eventBus); }); return this; }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); var builder = new ContainerBuilder(); var ctx1 = new RegisterUserContext(); var commandBus = new CommandBus(); commandBus.RegisterHandlerCommand<RegisterUserCommand>(ctx1.Handle); builder.Register<IBus>(c => commandBus).As<IBus>(); builder.RegisterControllers(Assembly.GetExecutingAssembly()); var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
public ProductController(ISessionFactory sf) { this.sf = sf; this._cmdBus = ServiceLocator.Bus; }
public async Task <IActionResult> DisableField(string app, string name, long id) { await CommandBus.PublishAsync(new DisableField { FieldId = id }); return(NoContent()); }
public LogMessageProcessingFailureController(CommandBus commandBus) { this.commandBus = commandBus; }
public async Task <IActionResult> DeleteSchema(string app, string name) { await CommandBus.PublishAsync(new DeleteSchema()); return(NoContent()); }
private void QueChannel(CommandBus bus) { using (IModel model = conn.CreateModel()) { var subscription = new Subscription(model, "queue", false); while (true) { BasicDeliverEventArgs basicDeliveryEventArgs = subscription.Next(); var @event = StreamExtension.Deserialize<Vaccine.Events.DomainEvent>(basicDeliveryEventArgs.Body); //Encoding.UTF8.GetString(basicDeliveryEventArgs.Body); Console.WriteLine(@event.GetType()); bus.Publish(@event); subscription.Ack(basicDeliveryEventArgs); } } }
public RunRabbitMQSubscriber(CommandBus bus) { this.bus = bus; Console.WriteLine("Creating factory..."); factory = new ConnectionFactory(); Console.WriteLine("Creating connection..."); factory.Protocol = Protocols.FromEnvironment(); factory.HostName = "localhost"; conn = factory.CreateConnection(); Console.WriteLine("Creating channel..."); try { QueChannel(bus); } catch { Thread.Sleep(100000); QueChannel(bus); } }
public async Task <IActionResult> DeleteSchema(string app, string name, Guid id) { await CommandBus.PublishAsync(new DeleteWebhook { Id = id }); return(NoContent()); }
private static void RegisterHandlers(IKernel kernel) { kernel.Bind( convention => convention.From(Assembly.GetAssembly(typeof(CommandBus))) .SelectAllClasses() .InNamespaces("WaiterManagement.BLL.Commands.Handlers") .BindAllInterfaces()); var commandBus = new CommandBus(x => kernel.GetAll<IHandleCommand>().First(y => y.GetType().GetInterfaces()[1].GetGenericArguments()[0] == x)); kernel.Bind<ICommandBus>().ToConstant(commandBus); kernel.Bind( convention => convention.From(Assembly.GetAssembly(typeof(EventBus))) .SelectAllClasses() .InNamespaces("WaiterManagement.BLL.Events.Handlers") .BindAllInterfaces()); kernel.Bind<IEventBus>().ToMethod(c => new EventBus(x => kernel.GetAll<IHandleEvent>().Where(y => y.GetType().GetInterfaces().Any(z => z.IsGenericType && z.GetGenericArguments()[0] == x)))); }
public async Task <IActionResult> PutNestedField(string app, string name, long parentId, long id, [FromBody] UpdateFieldDto request) { await CommandBus.PublishAsync(request.ToCommand(id, parentId)); return(NoContent()); }
public void Setup() { commandHandlerFactory = MockRepository.GenerateMock<ICommandHandlerFactory>(); commandBus = new CommandBus(commandHandlerFactory); }
public async Task <IActionResult> PutNestedFieldOrdering(string app, string name, long parentId, [FromBody] ReorderFieldsDto request) { await CommandBus.PublishAsync(request.ToCommand(parentId)); return(NoContent()); }
protected WorkflowHandler(ViewContext context, CommandBus commandBus, IEntityIdGenerator idGenerator) { _context = context; _commandBus = commandBus; _idGenerator = idGenerator; }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); var builder = new ContainerBuilder(); builder.RegisterModule(new NHibernateSessionModule()); //builder.RegisterModule(new ReportingSessionModule()); builder.RegisterModule(new QueryModule()); builder.RegisterControllers(Assembly.GetExecutingAssembly()); var container = builder.Build(); _container = container; QueryModule._container = _container; DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); var rabbitMQPublisher = new RabbitMQPublisher(System.Configuration.ConfigurationManager.AppSettings["CLOUDAMQP_URL"]); //Use RabbitMQ //var commandBus = new CommandBus(rabbitMQPublisher); var commandBus = new CommandBus(); var sessionFactory = container.Resolve<ISessionFactory>(); IEventStore eventStore = new NHibernateEventStore(commandBus, sessionFactory); //Context var transferMoneyContext = new TransferMoneyContext(eventStore); var createBankAccountContext = new CreateBankAccountContext(eventStore); var changeAccountAndBalanceContext = new ChangeAccountNameAndBalanceContext(eventStore); var createCustomerContext = new CreateCustomerContext(eventStore); var addCustomerAddressContext = new AddCustomerAddressContext(eventStore); var stockNewProductContext = new StockNewProductContext(eventStore); var placeOrderContext = new PlaceOrderContext(eventStore); //Register Command commandBus.RegisterHandlerCommand<OpenAccountCommand>(createBankAccountContext.Handle); commandBus.RegisterHandlerCommand<TransferMoneyCommand>(transferMoneyContext.Handle); commandBus.RegisterHandlerCommand<ChangeAccountNameAndBalanceCommand>(changeAccountAndBalanceContext.Handle); commandBus.RegisterHandlerCommand<CreateCustomerCommand>(createCustomerContext.Handle); commandBus.RegisterHandlerCommand<AddCustomerAddressCommand>(addCustomerAddressContext.Handle); commandBus.RegisterHandlerCommand<CreateProductCommand>(stockNewProductContext.Handle); commandBus.RegisterHandlerCommand<PlaceOrderCommand>(placeOrderContext.Handle); //Report View var accountReportView = new AccountReportView(sessionFactory); //Register Event commandBus.RegisterHandlerEvent<AccountCreatedEvent>(accountReportView.Handle); commandBus.RegisterHandlerEvent<AccountNameAndBalanceChangedEvent>(accountReportView.Handle); commandBus.RegisterHandlerEvent<BalanceDecreasedEvent>(accountReportView.Handle); commandBus.RegisterHandlerEvent<BalanceIncreasedEvent>(accountReportView.Handle); //Report View var customerReportView = new CustomerReportView(container.Resolve<ISessionFactory>()); //Register Event commandBus.RegisterHandlerEvent<CustomerCreatedEvent>(customerReportView.Handle); commandBus.RegisterHandlerEvent<CustomerAddressAddedEvent>(customerReportView.Handle); var placeOrderView = new PlaceOrderView(container.Resolve<ISessionFactory>()); commandBus.RegisterHandlerEvent<OrderPlacedEvent>(placeOrderView.Handle); var productStockReportView = new ProductStockReportView(container.Resolve<ISessionFactory>()); commandBus.RegisterHandlerEvent<ProductCreatedEvent>(productStockReportView.Handle); //ServiceLocator.Pub = rabbitMQPublisher; ServiceLocator.Bus = commandBus; //ServiceLocator.Sub = rabbitMQSubsriber; }
public async Task <IActionResult> ChangePlanAsync(string app, [FromBody] ChangePlanDto request) { await CommandBus.PublishAsync(SimpleMapper.Map(request, new ChangePlan())); return(NoContent()); }
private static UnityContainer CreateContainer() { var container = new UnityContainer(); // infrastructure var serializer = new JsonTextSerializer(); container.RegisterInstance<ITextSerializer>(serializer); #if LOCAL container.RegisterType<IMessageSender, MessageSender>( "Commands", new TransientLifetimeManager(), new InjectionConstructor(Database.DefaultConnectionFactory, "SqlBus", "SqlBus.Commands")); container.RegisterType<ICommandBus, CommandBus>( new ContainerControlledLifetimeManager(), new InjectionConstructor(new ResolvedParameter<IMessageSender>("Commands"), serializer)); #else var settings = InfrastructureSettings.Read(HttpContext.Current.Server.MapPath(@"~\bin\Settings.xml")).ServiceBus; new ServiceBusConfig(settings).Initialize(); var commandBus = new CommandBus(new TopicSender(settings, "conference/commands"), new StandardMetadataProvider(), serializer); container.RegisterInstance<ICommandBus>(commandBus); #endif // repository container.RegisterType<IBlobStorage, SqlBlobStorage>(new ContainerControlledLifetimeManager(), new InjectionConstructor("BlobStorage")); container.RegisterType<ConferenceRegistrationDbContext>(new TransientLifetimeManager(), new InjectionConstructor("ConferenceRegistration")); container.RegisterType<PaymentsReadDbContext>(new TransientLifetimeManager(), new InjectionConstructor("Payments")); container.RegisterType<IOrderDao, OrderDao>(); container.RegisterType<IConferenceDao, ConferenceDao>(); container.RegisterType<IPaymentDao, PaymentDao>(); return container; }
public async Task <IActionResult> DeleteNestedField(string app, string name, long parentId, long id) { await CommandBus.PublishAsync(new DeleteField { ParentFieldId = parentId, FieldId = id }); return(NoContent()); }
private void ConfigureCommands() { _kernel.Bind( convention => convention.From(Assembly.GetAssembly(typeof(CommandBus))) .SelectAllClasses() .InNamespaces("Organizer.BLL.Commands.Handlers") .BindAllInterfaces()); _kernel.Bind( convention => convention.From(Assembly.GetAssembly(typeof(CommandBus))) .SelectAllClasses() .InNamespaces("Organizer.BLL.Commands.Concrete") .BindAllInterfaces()); var commandBus = new CommandBus(x => _kernel.GetAll<IHandleCommand>().First(y => y.GetType().GetInterfaces()[1].GetGenericArguments()[0] == x)); _kernel.Bind<ICommandBus>().ToConstant(commandBus); }
public async Task <IActionResult> DeleteAssetFolder(string app, Guid id) { await CommandBus.PublishAsync(new DeleteAssetFolder { AssetFolderId = id }); return(NoContent()); }
public LogCommandProcessingController(CommandBus commandBus) { this.commandBus = commandBus; }
public BankAccountController(ISessionFactory sf) { this.sf = sf; this._cmdBus = ServiceLocator.Bus; }
public CustomerReportController(ISessionFactory sf) { this.sf = sf; this._cmdBus = ServiceLocator.Bus; }
public EnemiesWaveMaintainerSystem(CommandBus commandBus, EnemiesSettings enemiesSettings) { _commandBus = commandBus; _enemiesSettings = enemiesSettings; }