// 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)); }
public async Task StartAsync(CancellationToken cancellationToken) { var waiter = new DependencyAwaiter(); waiter.WaitForRabbit(Configuration.RabbitMqHost); await _busControl.StartAsync(cancellationToken); _logger.LogInformation("Running Shipping microservice."); }
// 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)); }
public void Run() { var waiter = new DependencyAwaiter(); waiter.WaitForRabbit(Configuration.RabbitMqHost); var builder = new ContainerBuilder(); builder.RegisterModule <BusModule>(); builder.RegisterModule <ConsumerModule>(); var container = builder.Build(); var bus = container.Resolve <IBusControl>(); bus.Start(); Logger.Info("Running Shipping microservice."); Thread.Sleep(int.MaxValue); }
// 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)); }