Last active
August 29, 2015 14:19
-
-
Save dcomartin/82a81fa4f5a217c50702 to your computer and use it in GitHub Desktop.
Unity Container with MediatR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void RegisterTypes(IUnityContainer container) | |
{ | |
container.RegisterType<IRepository>(new InjectionFactory(context => new EventStoreRepository(context.Resolve<IStoreEvents>(), new AggregateFactory(), new ConflictDetector()))); | |
container.RegisterType<IMediator>(new InjectionFactory(x => new Mediator(() => new UnityServiceLocator(x)))); | |
container.RegisterTypes(AllClasses.FromAssemblies(typeof(Commands.InventoryCommandHandler).Assembly), WithMappings.FromAllInterfaces, GetName, GetLifetimeManager); | |
container.RegisterTypes(AllClasses.FromAssemblies(typeof(Queries.InventoryQueryHandler).Assembly), WithMappings.FromAllInterfaces, GetName, GetLifetimeManager); | |
container.RegisterType<IStoreEvents>(new InjectionFactory(context => Wireup.Init() | |
.UsingSqlPersistence("EventStore") | |
.WithDialect(new MySqlDialect()) | |
.EnlistInAmbientTransaction() | |
.InitializeStorageEngine() | |
.UsingJsonSerialization() | |
.UsingSynchronousDispatchScheduler().DispatchTo(new DelegateMessageDispatcher(commit => { | |
var mediator = context.Resolve<IMediator>(); | |
foreach (var evnt in commit.Events) | |
{ | |
mediator.PublishAsync(evnt.Body as dynamic); | |
} | |
})) | |
.Build())); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment