Example #1
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, LibraryContext dbContext)
        {
            var logger = new LoggerConfiguration()
                         .ReadFrom
                         .Configuration(Configuration)
                         .CreateLogger();

            Log.Logger = logger;
            loggerFactory.AddSerilog();

            logger.Information("Logger configurado");

            app.UseStaticFiles();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/home/error");
            }

            // Basic CORS
            //app.UseCors(options =>
            //{
            //    options.WithOrigins("*");
            //});

            // CORS with policy
            app.UseCors("MyCorsPolicy");

            app.UseSession();

            app.UseIdentity();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "defaultRoute",
                    template: "{controller}/{action}/{id:int?}",
                    defaults: new { controller = "Home", action = "Index" }
                    );
            });

            logger.Information("MVC configurado");

            app.UseSwagger();

            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "My Library API");
            });

            logger.Information("Swagger configurado");

            if (env.IsDevelopment())
            {
                dbContext.EnsureSeedData();
            }
        }