private static IMediator BuildMediator() { var container = new Container(cfg => { cfg.Scan(scanner => { scanner.AssemblyContainingType<Ping>(); scanner.AssemblyContainingType<IMediator>(); scanner.WithDefaultConventions(); scanner.AddAllTypesOf(typeof(IRequestHandler<,>)); scanner.AddAllTypesOf(typeof(IAsyncRequestHandler<,>)); scanner.AddAllTypesOf(typeof(INotificationHandler<>)); scanner.AddAllTypesOf(typeof(IAsyncNotificationHandler<>)); }); cfg.For<TextWriter>().Use(Console.Out); }); var serviceLocator = new StructureMapServiceLocator(container); var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator); container.Configure(cfg => cfg.For<ServiceLocatorProvider>().Use(serviceLocatorProvider)); var mediator = serviceLocator.GetInstance<IMediator>(); return mediator; }
private static IMediator BuildMediator() { var container = new Container(cfg => { cfg.Scan(scanner => { scanner.AssemblyContainingType <Ping>(); scanner.AssemblyContainingType <IMediator>(); scanner.WithDefaultConventions(); scanner.AddAllTypesOf(typeof(IRequestHandler <,>)); scanner.AddAllTypesOf(typeof(IAsyncRequestHandler <,>)); scanner.AddAllTypesOf(typeof(INotificationHandler <>)); scanner.AddAllTypesOf(typeof(IAsyncNotificationHandler <>)); }); cfg.For <TextWriter>().Use(Console.Out); }); var serviceLocator = new StructureMapServiceLocator(container); var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator); container.Configure(cfg => cfg.For <ServiceLocatorProvider>().Use(serviceLocatorProvider)); var mediator = serviceLocator.GetInstance <IMediator>(); return(mediator); }