refact
This commit is contained in:
parent
93394b3e82
commit
6a59f776d5
223 changed files with 75 additions and 8 deletions
106
src/nuget-host/Startup.cs
Normal file
106
src/nuget-host/Startup.cs
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
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<ApplicationDbContext>(options =>
|
||||
options.UseNpgsql(
|
||||
Configuration.GetConnectionString("DefaultConnection")));
|
||||
|
||||
|
||||
services.AddIdentity<ApplicationUser, IdentityRole>()
|
||||
.AddEntityFrameworkStores<ApplicationDbContext>()
|
||||
.AddSignInManager()
|
||||
.AddDefaultUI()
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
services.AddMvc();
|
||||
|
||||
services.AddDataProtection();
|
||||
services.AddTransient<IMailer, EmailSender>();
|
||||
services.AddTransient<IEmailSender, EmailSender>();
|
||||
|
||||
var smtpSettingsconf = Configuration.GetSection("Smtp");
|
||||
services.Configure<SmtpSettings>(smtpSettingsconf);
|
||||
var nugetSettingsconf = Configuration.GetSection("Nuget");
|
||||
services.Configure<NugetSettings>(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?}");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue