public static IContainer UseDispatcher(this IContainer container) { Assembly applicationServices = ApplicationServiceGenerator.Generate(typeof(UserAggregate).Assembly); Dispatcher dispatcher = DispatcherExtensions.Create(config => { config.HandlersTypesResolver = type => { bool isDispatcherHandler = type.IsDefined(typeof(DispatcherHandlerAttribute)); bool isApplicationService = type.BaseType != null && type.BaseType.IsGenericType && typeof(ApplicationService <>).IsAssignableFrom(type.BaseType?.GetGenericTypeDefinition()); return(isDispatcherHandler || isApplicationService); }; config.RegisterHandlers(applicationServices); //config.RegisterHandlers(typeof(WorkflowService).Assembly); config.RegisterHandlers(typeof(IView).Assembly); config.SetServiceProvider(new StructureMapServiceProvider(container)); config.AddInterceptor <ConsoleInterceptor>(); config.ThrowIfMultipleSendingHandlersFound = true; }); container.Configure(expression => expression.For <Dispatcher>().Use(dispatcher).Singleton()); return(container); }
public static IContainer UseAsyncDispatcherSingleton(this IContainer container) { Assembly assemblyWithAggregates = ApplicationServiceGenerator.Generate(typeof(UserAggregate).Assembly); AsyncMessageDispatcher dispatcher = DispatcherFactory.CreateAsync(configuration => { configuration.SetServiceLocator(new StructureMapServiceProvider(container)); configuration.AddScanRule(assemblyWithAggregates); //scan for command handlers configuration.AddScanRule(typeof(Event).Assembly); //scan for command handlers configuration.AddScanRule(typeof(_namespace).Assembly); //scan for event and query handlers configuration.EnableHandlingPriority(); //configuration.AddInterceptor<LoggingInterceptor>(); }); container.Configure(expression => expression.For <AsyncMessageDispatcher>().Use(dispatcher).Singleton()); return(container); }