isn/Startup.cs

94 lines
3.1 KiB
C#

4 years ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
4 years ago
using Microsoft.AspNetCore.DataProtection;
4 years ago
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
4 years ago
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;
4 years ago
namespace nuget_host
{
public class Startup
{
4 years ago
public Startup(IConfiguration config)
4 years ago
{
Configuration = config;
}
public IConfiguration Configuration { get; }
public static string ExternalUrl { get; private set; }
public static string SourceDir { get; private set; }
4 years ago
public static string RootApiKeySecret { get; private set; }
4 years ago
// 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")));
4 years ago
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddSignInManager()
.AddDefaultUI()
.AddDefaultTokenProviders();
4 years ago
services.AddMvc();
4 years ago
services.AddDataProtection();
services.AddTransient<IMailer, EmailSender>();
services.AddTransient<IEmailSender, EmailSender>();
4 years ago
var smtpSettingsconf = Configuration.GetSection("SmtpSettings");
services.Configure<SmtpSettings>(smtpSettingsconf);
3 years ago
4 years ago
}
// 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)
4 years ago
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseMigrationsEndPoint();
4 years ago
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
4 years ago
}
ExternalUrl = Configuration["NuGet:ExternalUrl"];
SourceDir = Configuration["NuGet:SourceDir"];
4 years ago
RootApiKeySecret = Configuration["RootApiKeySecret"];
4 years ago
app.UseStaticFiles();
app.UseHttpsRedirection();
app.UseAuthentication();
4 years ago
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}