From 91720c57255c7535bf8168fcb3bfd46747989f55 Mon Sep 17 00:00:00 2001 From: johnmcavinue Date: Wed, 11 May 2016 14:32:18 +0100 Subject: [PATCH] CommandBus now aggregated in UserAccountService. 642 --- .../AccountService/UserAccountService.cs | 8 ++++++-- src/BrockAllen.MembershipReboot/Bus/CommandBus.cs | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/BrockAllen.MembershipReboot/AccountService/UserAccountService.cs b/src/BrockAllen.MembershipReboot/AccountService/UserAccountService.cs index 01afc675..3819fb04 100644 --- a/src/BrockAllen.MembershipReboot/AccountService/UserAccountService.cs +++ b/src/BrockAllen.MembershipReboot/AccountService/UserAccountService.cs @@ -18,6 +18,7 @@ public class UserAccountService : IEventSource public MembershipRebootConfiguration Configuration { get; set; } EventBusUserAccountRepository userRepository; + AggregateCommandBus aggregateCommandBus; Lazy> usernameValidator; Lazy> emailValidator; @@ -37,6 +38,10 @@ public UserAccountService(MembershipRebootConfiguration configuration, this.Configuration = configuration; + aggregateCommandBus = new AggregateCommandBus() { + commandBus, configuration.CommandBus + }; + var validationEventBus = new EventBus(); validationEventBus.Add(new UserAccountValidator(this)); this.userRepository = new EventBusUserAccountRepository(this, userRepository, @@ -136,8 +141,7 @@ public void AddCommandHandler(ICommandHandler handler) CommandBus commandBus = new CommandBus(); protected internal void ExecuteCommand(ICommand cmd) { - commandBus.Execute(cmd); - Configuration.CommandBus.Execute(cmd); + aggregateCommandBus.Execute(cmd); } public virtual IUserAccountQuery Query diff --git a/src/BrockAllen.MembershipReboot/Bus/CommandBus.cs b/src/BrockAllen.MembershipReboot/Bus/CommandBus.cs index b25a4a1e..10d73fec 100644 --- a/src/BrockAllen.MembershipReboot/Bus/CommandBus.cs +++ b/src/BrockAllen.MembershipReboot/Bus/CommandBus.cs @@ -51,4 +51,14 @@ where eventHandlerType.IsAssignableFrom(handler.GetType()) return handlerCache[eventType]; } } + class AggregateCommandBus : List, ICommandBus + { + public void Execute(ICommand evt) + { + foreach (var eb in this) + { + eb.Execute(evt); + } + } + } }