// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { ProfileServiceDatabaseConfiguration databaseConfig = new ProfileServiceDatabaseConfiguration(Configuration, null); // Configure DBContexts services.AddDbContext <ProfileServiceDbContext>(options => databaseConfig.BuildDBContext(options)); // Add MVC services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddRawRabbit(options => { options.SetBasePath(Environment.ContentRootPath) .AddJsonFile("rawrabbit.json") .AddEnvironmentVariables("RawRabbit:"); }); // Configure Swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info { Title = "Profile Service API", Version = "v1" }); }); // Additional Configuration services.AddHttpContextAccessor(); services.AddSingleton <ContextServiceLocator>(); services.AddSingleton <Hosting.IHostedService, ProfileMessageHandlerService>(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { // Change the Root Path of the Profile app.UsePathBase($"/{SERVICE_ENDPOINT_REWRITE}"); // Initialize our Databases try { ProfileServiceDatabaseConfiguration databaseConfig = new ProfileServiceDatabaseConfiguration(Configuration, app); databaseConfig.InitializeDatabase(app); } catch (Exception) { } // Configure our Error Pages if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } // Setup http to https redirection app.UseHttpsRedirection(); // Enable Swagger Middleware app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint($"/{SERVICE_ENDPOINT_REWRITE}/swagger/v1/swagger.json", "Profile Service API"); }); _logger.LogInformation("Waiting for rabbitmq..."); // Block until the rabbitmq panel is online NetworkingHelpers.WaitForOk(new Uri("http://rabbitmq:15672")).Wait(); _logger.LogInformation("rabbitmq is ready"); // Setup MVC with a Default Route //app.UseMvcWithDefaultRoute(); app.UseMvc(); }