private static void Main() { using (var container = new Container()) { container.Options.AllowResolvingFuncFactories(); // configuration appsettings convention IConfiguration configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true) .AddEnvironmentVariables() .Build(); container.Options.RegisterParameterConvention(new AppSettingsConvention(key => configuration[key])); ILoggerFactory loggerFactory = new LoggerFactory() .AddConsole() .AddDebug(); container.Options.DependencyInjectionBehavior = new MsContextualLoggerInjectionBehavior(loggerFactory, container); ILogger logger = loggerFactory.CreateLogger <Program>(); //container.RegisterSingleton<ILogger>(logger); logger.LogInformation("Starting BC 'KmStanden' host..."); ExampleCQRS.Infrastructure.Registrations.InfrastructureModule.RegisterEventBus(container, configuration); DomainModule.RegisterAll(container); ApplicationModule.RegisterAll(container); InfrastructureModule.RegisterAll(container); InfrastructureModule.RegisterEventForwarder(container); RabbitMqModule.RegisterCommandConsumers(container); var bus = Bus.Factory.CreateUsingRabbitMq(cfg => { var host = cfg.Host(new Uri(configuration["CommandBusConnection"]), hst => { hst.Username(configuration["CommandBusUserName"]); hst.Password(configuration["CommandPassword"]); }); cfg.SeparatePublishFromSendTopology(); // command queue cfg.ReceiveEndpoint(host, RabbitMqConstants.CommandsQueue, e => { e.LoadFrom(container); }); }); container.RegisterSingleton(bus); //container.RegisterSingleton(RabbitMqConfiguration.ConfigureBus((cfg, host) => //{ // cfg.SeparatePublishFromSendTopology(); // // command queue // cfg.ReceiveEndpoint(host, // RabbitMqConstants.CommandsQueue, e => // { // e.LoadFrom(container); // }); //})); using (var eventBus = container.GetInstance <IIntegrationEventBus>()) { var cbus = container.GetInstance <IBusControl>(); cbus.StartAsync(); Console.WriteLine("Listening for commands.. Press enter to exit"); Console.ReadLine(); cbus.StopAsync(); } } }
private static void Main() { using (var container = new Container()) { container.Options.AllowResolvingFuncFactories(); // configuration appsettings convention IConfiguration config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true) .AddEnvironmentVariables() .Build(); container.Options.RegisterParameterConvention(new AppSettingsConvention(key => config[key])); ILoggerFactory loggerFactory = new LoggerFactory() .AddConsole() .AddDebug(); container.Options.DependencyInjectionBehavior = new MsContextualLoggerInjectionBehavior(loggerFactory, container); ILogger logger = loggerFactory.CreateLogger <Program>(); //container.RegisterSingleton<ILogger>(logger); logger.LogInformation("Starting BC 'Ritten' host..."); ExampleCQRS.Infrastructure.Registrations.InfrastructureModule.RegisterEventBus(container, config); DomainModule.RegisterAll(container); ApplicationModule.RegisterAll(container); InfrastructureModule.RegisterAll(container); InfrastructureModule.RegisterEventForwarder(container); RabbitMqModule.RegisterCommandConsumers(container); RabbitMqModule.RegisterEventConsumers(container); //ReadModel.Infrastructure.Registrations.InfrastructureModule.RegisterAll(container); container.RegisterSingleton(RabbitMqConfiguration.ConfigureBus((cfg, host) => { // command queue //cfg.ReceiveEndpoint(host, // RabbitMqConstants.CommandsQueue, e => // { // e.Handler<ICommand>(context => // Console.Out.WriteLineAsync($"Command received : {context.Message.GetType()}")); // //e.LoadFrom(container);// TODO: prevent receiving same events // }); // events queue cfg.ReceiveEndpoint(host, RabbitMqConstants.GetEventsQueue(BoundedContextName), e => { e.Handler <IDomainEvent>(context => Console.Out.WriteLineAsync($"Event received : {context.Message.GetType()}")); e.LoadFrom(container); }); })); EventMappings.Configure(); var eventBus = container.GetInstance <IIntegrationEventBus>(); eventBus.Subscribe <KmStandCreated, RitService>(); //var bus = container.GetInstance<IBusControl>(); //bus.StartAsync(); Console.WriteLine("Listening for commands.. Press enter to exit"); Console.ReadLine(); //bus.StopAsync(); } }