Skip to content
This repository has been archived by the owner on Dec 14, 2017. It is now read-only.

Commit

Permalink
CommandBus now aggregated in UserAccountService. 642
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMcAvinue committed May 11, 2016
1 parent 8f6e43c commit 91720c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class UserAccountService<TAccount> : IEventSource
public MembershipRebootConfiguration<TAccount> Configuration { get; set; }

EventBusUserAccountRepository<TAccount> userRepository;
AggregateCommandBus aggregateCommandBus;

Lazy<AggregateValidator<TAccount>> usernameValidator;
Lazy<AggregateValidator<TAccount>> emailValidator;
Expand All @@ -37,6 +38,10 @@ public UserAccountService(MembershipRebootConfiguration<TAccount> configuration,

this.Configuration = configuration;

aggregateCommandBus = new AggregateCommandBus() {
commandBus, configuration.CommandBus
};

var validationEventBus = new EventBus();
validationEventBus.Add(new UserAccountValidator<TAccount>(this));
this.userRepository = new EventBusUserAccountRepository<TAccount>(this, userRepository,
Expand Down Expand Up @@ -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<TAccount> Query
Expand Down
10 changes: 10 additions & 0 deletions src/BrockAllen.MembershipReboot/Bus/CommandBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,14 @@ where eventHandlerType.IsAssignableFrom(handler.GetType())
return handlerCache[eventType];
}
}
class AggregateCommandBus : List<ICommandBus>, ICommandBus
{
public void Execute(ICommand evt)
{
foreach (var eb in this)
{
eb.Execute(evt);
}
}
}
}

0 comments on commit 91720c5

Please sign in to comment.