// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { // Azure Active Directory Authentication services.AddAuthentication(sharedOptions => { sharedOptions.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddAzureAdBearer(options => Configuration.Bind("AzureAd", options)); // MVC services.AddMvc(setup => { if (!HostingEnvironment.IsDevelopment()) { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); setup.Filters.Add(new AuthorizeFilter(policy)); } }); // Compression services.Configure <GzipCompressionProviderOptions>(options => options.Level = System.IO.Compression.CompressionLevel.Optimal); services.AddResponseCompression(); // Cors services.AddCors(); // Register the Swagger generator, defining 1 or more Swagger documents services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Northwind BackOffice Web API", Version = "v1" }); }); Runtime.ConnectionString = Configuration.GetConnectionString("DefaultConnection"); MapperExtension.RegisterProfiles(); // Add DbContext services.AddDbContext <IntegrationEventLogContext>(options => options.UseSqlServer(Runtime.ConnectionString)); services.AddDbContext <SalesDbContext>(options => options.UseSqlServer(Runtime.ConnectionString)); // Add Configuration services.AddSingleton <IConfiguration>(Configuration); // Add RabittMq Settings services.AddSingleton(service => { var settings = Configuration.GetSection("RabbitMqSettings"); var bus = Bus.Factory.CreateUsingRabbitMq(cfg => { cfg.ExchangeType = ExchangeType.Direct; cfg.Durable = true; cfg.AutoDelete = false; cfg.Host(new Uri(settings.GetValue <string>("RabbitMqUri")), host => { host.Username(settings.GetValue <string>("UserName")); host.Password(settings.GetValue <string>("Password")); }); }); ApplicationLifetime.ApplicationStopped.Register(bus.Stop); TaskUtil.Await(() => bus.StartAsync()); return(bus); }); services.AddTransient <Func <DbConnection, IntegrationEventLogService> >( sp => (DbConnection c) => new IntegrationEventLogService(c)); services.AddTransient <IntegrationEventLogService>(); services.AddTransient <IProductIntegrationEventService, ProductIntegrationEventService>(); }
static ContainerDrivenScenario() { MapperExtension.RegisterProfiles(); }