using System; using Bit.Core; using Bit.Core.Identity; using Bit.Core.Utilities; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Serilog.Events; using Stripe; namespace Bit.Admin { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } public void ConfigureServices(IServiceCollection services) { // Options services.AddOptions(); // Settings var globalSettings = services.AddGlobalSettingsServices(Configuration); services.Configure(Configuration.GetSection("AdminSettings")); // Stripe Billing StripeConfiguration.SetApiKey(globalSettings.StripeApiKey); // Repositories services.AddSqlServerRepositories(globalSettings); // Context services.AddScoped(); // Identity services.AddPasswordlessIdentityServices(globalSettings); // Services services.AddBaseServices(); services.AddDefaultServices(globalSettings); // Mvc services.AddMvc(config => { config.Filters.Add(new LoggingExceptionHandlerFilterAttribute()); }); services.Configure(options => options.LowercaseUrls = true); } public void Configure( IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime appLifetime, GlobalSettings globalSettings, ILoggerFactory loggerFactory) { loggerFactory.AddSerilog(app, env, appLifetime, globalSettings, (e) => e.Level >= LogEventLevel.Error); if(globalSettings.SelfHosted) { app.UsePathBase("/admin"); } if(env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseAuthentication(); app.UseStaticFiles(); app.UseMvcWithDefaultRoute(); } } }