Example #1
0
 public RentalsController(RentalManagementDBContext dbContext, IMessagePublisher messagePublisher)
 {
     _dbContext        = dbContext;
     _messagePublisher = messagePublisher;
 }
Example #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime lifetime, RentalManagementDBContext dbContext)
        {
            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(_configuration)
                         .Enrich.WithMachineName()
                         .CreateLogger();

            app.UseMvc();
            app.UseDefaultFiles();
            app.UseStaticFiles();

            SetupAutoMapper();

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS etc.), specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "RentalManagement API - v1");
            });

            // auto migrate db
            using (var scope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                scope.ServiceProvider.GetService <RentalManagementDBContext>().MigrateDB();
            }
        }