// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); // Logging services.AddLogging(builder => { builder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Debug); builder.AddConsole(); builder.AddDebug(); }); //DbContext services.AddDbContext <CustomerContext>(o => o.UseSqlServer(Configuration.GetConnectionString("EventuateDB"), x => x.MigrationsHistoryTable("__EFMigrationsHistoryCustomer"))); // Kafka Transport services.AddEventuateTramSqlKafkaTransport(Configuration.GetSection("EventuateTramDbSchema").Value, Configuration.GetSection("KafkaBootstrapServers").Value, EventuateKafkaConsumerConfigurationProperties.Empty(), (provider, o) => { var applicationDbContext = provider.GetRequiredService <CustomerContext>(); o.UseSqlServer(applicationDbContext.Database.GetDbConnection()); }); // Publisher services.AddEventuateTramEventsPublisher(); // Dispatcher services.AddScoped <OrderEventConsumer>(); services.AddEventuateTramDomainEventDispatcher(Guid.NewGuid().ToString(), provider => DomainEventHandlersBuilder.ForAggregateType("Order") .OnEvent <OrderCreatedEvent, OrderEventConsumer>() .OnEvent <OrderCancelledEvent, OrderEventConsumer>() .Build()); // Repository services.AddTransient <ICustomerRepository, CustomerRepository>(); // Service services.AddScoped <Service.CustomerService>(); }
public DomainEventHandlers domainEventHandlers() { return(DomainEventHandlersBuilder .ForAggregateType(aggregateType) .OnEvent <MyDomainEvent>(HandleAccountDebited) .Build()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); //DbContext services.AddDbContext <OrderContext>(o => o.UseSqlServer(Configuration.GetConnectionString("EventuateDB"), x => x.MigrationsHistoryTable("__EFMigrationsHistoryOrder"))); // Kafka Transport services.AddEventuateTramSqlKafkaTransport(Configuration.GetSection("EventuateTramDbSchema").Value, Configuration.GetSection("KafkaBootstrapServers").Value, EventuateKafkaConsumerConfigurationProperties.Empty(), (provider, o) => { var applicationDbContext = provider.GetRequiredService <OrderContext>(); o.UseSqlServer(applicationDbContext.Database.GetDbConnection()); }); // Publisher services.AddEventuateTramEventsPublisher(); // Dispatcher services.AddScoped <CustomerEventConsumer>(); services.AddEventuateTramDomainEventDispatcher(Guid.NewGuid().ToString(), provider => DomainEventHandlersBuilder.ForAggregateType("Customer") .OnEvent <CustomerCreditReservedEvent, CustomerEventConsumer>() .OnEvent <CustomerValidationFailedEvent, CustomerEventConsumer>() .OnEvent <CustomerCreditReservationFailedEvent, CustomerEventConsumer>() .Build()); // Repository services.AddTransient <IOrderRepository, OrderRepository>(); // Service services.AddScoped <Service.OrderService>(); }
public DomainEventHandlers DomainEventHandlers(String aggregateType12, String aggregateType34) { return(DomainEventHandlersBuilder.ForAggregateType(aggregateType12) .OnEvent <TestMessageType1>(HandleMessageType1Event) .OnEvent <TestMessageType2>(HandleMessageType2Event) .AndForAggregateType(aggregateType34) .OnEvent <TestMessageType3>(HandleMessageType3Event) .OnEvent <TestMessageType4, TestMessage4Handler>() .Build()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); // Logging services.AddLogging(builder => { builder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Debug); builder.AddConsole(); builder.AddDebug(); }); var config = new ServerConfig(); Configuration.Bind(config); var orderHistoryContext = new OrderHistoryContext(config.MongoDB); var repo = new CustomerViewRepository(orderHistoryContext); services.AddSingleton <ICustomerViewRepository>(repo); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Latest).AddJsonOptions(opts => { opts.JsonSerializerOptions.Converters.Add(new CustomDictionaryJsonConverter <long, OrderInfo>()); }); // Kafka Transport services.AddEventuateTramSqlKafkaTransport(Configuration.GetSection("EventuateTramDbSchema").Value, Configuration.GetSection("KafkaBootstrapServers").Value, EventuateKafkaConsumerConfigurationProperties.Empty(), (provider, o) => { o.UseSqlServer(Configuration.GetSection("EventuateTramDbConnection").Value); }); // Publisher services.AddEventuateTramEventsPublisher(); // Dispatcher services.AddScoped <OrderHistoryEventConsumer>(); services.AddEventuateTramDomainEventDispatcher(Guid.NewGuid().ToString(), provider => DomainEventHandlersBuilder.ForAggregateType("Order") .OnEvent <OrderCreatedEvent, OrderHistoryEventConsumer>() .OnEvent <OrderApprovedEvent, OrderHistoryEventConsumer>() .OnEvent <OrderRejectedEvent, OrderHistoryEventConsumer>() .OnEvent <OrderCancelledEvent, OrderHistoryEventConsumer>() .AndForAggregateType("Customer") .OnEvent <CustomerCreatedEvent, OrderHistoryEventConsumer>() .Build()); // Service services.AddScoped <OrderHistoryViewService>(); }
public void Setup() { var host = new HostBuilder() .ConfigureServices((hostContext, services) => { //DbContext services.AddDbContext <OrderContext>(o => o.UseSqlServer(TestSettings.EventuateDB)); // Kafka Transport services.AddEventuateTramSqlKafkaTransport(TestSettings.EventuateTramDbSchema, TestSettings.KafkaBootstrapServers, EventuateKafkaConsumerConfigurationProperties.Empty(), (provider, o) => { var applicationDbContext = provider.GetRequiredService <OrderContext>(); applicationDbContext.Database.Migrate(); o.UseSqlServer(applicationDbContext.Database.GetDbConnection()); }); // Publisher services.AddEventuateTramEventsPublisher(); // Consumer services.AddSingleton <TestEventConsumer>(); // Dispatcher services.AddEventuateTramDomainEventDispatcher(Guid.NewGuid().ToString(), provider => DomainEventHandlersBuilder.ForAggregateType(typeof(Order).Name) .OnEvent <OrderCreatedEvent, TestEventConsumer>() .OnEvent <OrderCancelledEvent, TestEventConsumer>() .OnEvent <OrderRejectedEvent, TestEventConsumer>() .OnEvent <OrderApprovedEvent, TestEventConsumer>() .Build()); // Repository services.AddTransient <IOrderRepository, OrderRepository>(); }).Build(); host.StartAsync().Wait(); //Services domainEventPublisher = host.Services.GetService <IDomainEventPublisher>(); consumer = host.Services.GetService <TestEventConsumer>(); var orderRepository = host.Services.GetService <IOrderRepository>(); orderService = new OrderService.Service.OrderService(orderRepository, domainEventPublisher); //Initialize Money Money orderTotal = new Money("12.10"); orderDetails = new OrderDetails(1, orderTotal); }
public static IServiceCollection AddMercuryBus(this IServiceCollection services) { services.AddSingleton <IMessageHandlerDecorator, MercuryExecutionStrategyMessageHandlerDecorator>(); services.AddScoped <IDomainEventHandler <BlogCreatedEvent>, BlogCreatedEventHandler>(); services.AddMercuryBusSqlKafkaTransport("mercury", Configuration["Settings:KafkaBoostrapServers"], MercuryKafkaConsumerConfigurationProperties.Empty(), (serviceProvider, dbContextOptions) => { var appDbContext = serviceProvider.GetRequiredService <IdentityContext>(); dbContextOptions.UseSqlServer(appDbContext.Database.GetDbConnection()); }); services.AddMercuryBusEventsPublisher(); services.AddMercuryBusDomainEventDispatcher("identity-control-api", provider => DomainEventHandlersBuilder.ForAggregateType("Blog") .OnEvent <BlogCreatedEvent, IDomainEventHandler <BlogCreatedEvent> >() .Build()); return(services); }