Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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()
.WithDialect(new MySqlDialect())
.UsingSynchronousDispatchScheduler().DispatchTo(new DelegateMessageDispatcher(commit => {
var mediator = context.Resolve<IMediator>();
foreach (var evnt in commit.Events)
mediator.PublishAsync(evnt.Body as dynamic);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment