Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomartin/82a81fa4f5a217c50702 to your computer and use it in GitHub Desktop.
Save dcomartin/82a81fa4f5a217c50702 to your computer and use it in GitHub Desktop.
Unity Container with MediatR
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