Ejemplo n.º 1
0
        public static IServiceCollection AddApplication(this IServiceCollection services)
        {
            services.AddScoped <CourseCreator, CourseCreator>();

            services.AddScoped <CoursesCounterIncrementer, CoursesCounterIncrementer>();
            services.AddScoped <CoursesCounterFinder, CoursesCounterFinder>();
            services.AddScoped <IncrementCoursesCounterOnCourseCreated, IncrementCoursesCounterOnCourseCreated>();

            services.AddDomainEventSubscriberInformationService(MoocAssemblyHelper.Instance());
            services.AddCommandServices(MoocAssemblyHelper.Instance());
            services.AddQueryServices(MoocAssemblyHelper.Instance());
            return(services);
        }
Ejemplo n.º 2
0
        private static ServiceProvider CommandServicesProvider()
        {
            var services = new ServiceCollection();

            services.AddApplication();
            services.AddInfrastructure(Configuration());
            services.AddDomainEventSubscriberInformationService(MoocAssemblyHelper.Instance());

            services.AddScoped <ConsumeRabbitMqDomainEventsCommand, ConsumeRabbitMqDomainEventsCommand>();
            services.AddScoped <ConsumeMsSqlDomainEventsCommand, ConsumeMsSqlDomainEventsCommand>();

            var serviceProvider = services.BuildServiceProvider();

            return(serviceProvider);
        }
Ejemplo n.º 3
0
        protected override Action <IServiceCollection> Services()
        {
            return(services =>
            {
                var descriptor = services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions <MoocContext>));
                if (descriptor != null)
                {
                    services.Remove(descriptor);
                }

                IConfigurationRoot configuration = new ConfigurationBuilder()
                                                   .SetBasePath(AppContext.BaseDirectory)
                                                   .AddJsonFile("appsettings.json")
                                                   .Build();

                services.AddScoped <MsSqlEventBus, MsSqlEventBus>();
                services.AddScoped <MsSqlDomainEventsConsumer, MsSqlDomainEventsConsumer>();

                services.AddScoped <RabbitMqEventBus>(p =>
                {
                    var publisher = p.GetRequiredService <RabbitMqPublisher>();
                    var failOverBus = p.GetRequiredService <MsSqlEventBus>();
                    return new RabbitMqEventBus(publisher, failOverBus, "test_domain_events");
                });
                services.AddScoped <IEventBusConfiguration, RabbitMqEventBusConfiguration>();

                services.AddScoped <DomainEventsInformation, DomainEventsInformation>();

                services.AddScoped <TestAllWorksOnRabbitMqEventsPublished, TestAllWorksOnRabbitMqEventsPublished>();

                services.AddDomainEventSubscriberInformationService(MoocAssemblyHelper.Instance());
                services.AddCommandServices(MoocAssemblyHelper.Instance());
                services.AddQueryServices(MoocAssemblyHelper.Instance());

                services.AddDbContext <MoocContext>(options =>
                                                    options.UseSqlServer(configuration.GetConnectionString("MoocDatabase")));

                services.Configure <RabbitMqConfig>(configuration.GetSection("RabbitMq"));
            });
        }