Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            var rabbitHost = Configuration["RabbitHost"];

            Logger.Info($"Using RabbitHost='{rabbitHost}'.");

            var connectionString = Configuration["ConnectionString"];

            Logger.Info($"Using connectionString='{connectionString}'.");

            var waiter = new DependencyAwaiter();

            waiter.WaitForRabbit(rabbitHost);
            waiter.WaitForSql(connectionString);

            services.AddMvc();

            var builder = new ContainerBuilder();

            builder.Populate(services);
            builder.RegisterModule <BusModule>();
            builder.RegisterModule <ConsumerModule>();

            builder.RegisterType <DataService>().As <IDataService>().SingleInstance();
            builder.RegisterType <OrderRepository>().As <IOrderRepository>().SingleInstance();

            Container = builder.Build();

            return(new AutofacServiceProvider(Container));
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var rabbitHost = Configuration["RabbitHost"];

            Console.WriteLine($"Using RabbitHost='{rabbitHost}'.");

            var connectionString = Configuration["ConnectionString"];

            Console.WriteLine($"Using connectionString='{connectionString}'.");

            var waiter = new DependencyAwaiter();

            waiter.WaitForRabbit(rabbitHost);
            waiter.WaitForSql(connectionString);

            services.AddMvc();
            services.AddScoped <ICustomerRepository>(c => new CustomerRepository(connectionString));
        }
Exemplo n.º 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            var rabbitHost = Configuration["RabbitHost"];

            Logger.Info($"Using RabbitHost='{rabbitHost}'.");

            var connectionString = Configuration["ConnectionString"];

            Logger.Info($"Using connectionString='{connectionString}'.");

            var waiter = new DependencyAwaiter();

            waiter.WaitForRabbit(rabbitHost);
            waiter.WaitForSql(connectionString);

            services.AddMvc();

            services.AddEntityFrameworkSqlServer()
            .AddDbContext <SalesContext>(options =>
            {
                options.UseSqlServer(Configuration["ConnectionString"],
                                     sqlServerOptionsAction: sqlOptions =>
                {
                    sqlOptions.EnableRetryOnFailure(maxRetryCount: 10, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
                });
            },
                                         ServiceLifetime.Scoped //Showing explicitly that the DbContext is shared across the HTTP request scope (graph of objects started in the HTTP request)
                                         );

            var builder = new ContainerBuilder();

            builder.Populate(services);
            builder.RegisterModule <BusModule>();
            builder.RegisterModule <ConsumerModule>();
            builder.RegisterType <DataService>().As <IDataService>().SingleInstance();

            Container = builder.Build();

            return(new AutofacServiceProvider(Container));
        }