Пример #1
0
        // 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>();
        }
Пример #2
0
        public WhenGettingCustomersFromCustomerView()
        {
            DbContext _db = new ApplicationContext();

            _repo = new CustomerViewRepository(_db);
        }