using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.UI; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Identity.UI.Services; using Microsoft.Extensions.Hosting; using nuget_host.Data; using nuget_host.Interfaces; using nuget_host.Services; using nuget_host.Entities; using nuget_host.Models; using System.Reflection; namespace nuget_host { public class Startup { public Startup(IConfiguration config) { Configuration = config; } public IConfiguration Configuration { get; } public static string RootApiKeySecret { get; private set; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext(options => options.UseNpgsql( Configuration.GetConnectionString("DefaultConnection"))); services.AddIdentity() .AddEntityFrameworkStores() .AddSignInManager() .AddDefaultUI() .AddDefaultTokenProviders(); services.AddMvc(); services.AddDataProtection(); services.AddTransient(); services.AddTransient(); var smtpSettingsconf = Configuration.GetSection("Smtp"); services.Configure(smtpSettingsconf); var nugetSettingsconf = Configuration.GetSection("Nuget"); services.Configure(nugetSettingsconf); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env, ApplicationDbContext dbContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseMigrationsEndPoint(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); try { dbContext.Database.Migrate(); } catch (TargetInvocationException ex) { if (ex.InnerException is InvalidOperationException) // nothing to do ? { // TODO (or not) Hit the developper } else throw ex; } } app.UseStaticFiles(); app.UseHttpsRedirection(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); } } }