1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-29 13:25:17 +01:00
bitwarden-server/src/Billing/Startup.cs

97 lines
3.0 KiB
C#
Raw Normal View History

2017-03-18 23:52:44 +01:00
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Bit.Core;
using Stripe;
using Bit.Core.Utilities;
using Serilog.Events;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection.Extensions;
2018-03-20 20:00:56 +01:00
using Bit.Core.Identity;
using Microsoft.AspNetCore.Routing;
2017-03-18 23:52:44 +01:00
namespace Bit.Billing
{
public class Startup
{
public Startup(IConfiguration configuration)
2017-03-18 23:52:44 +01:00
{
Configuration = configuration;
2017-03-18 23:52:44 +01:00
}
public IConfiguration Configuration { get; }
2017-03-18 23:52:44 +01:00
public void ConfigureServices(IServiceCollection services)
{
// Options
services.AddOptions();
// Settings
var globalSettings = services.AddGlobalSettingsServices(Configuration);
2017-05-06 15:15:07 +02:00
services.Configure<BillingSettings>(Configuration.GetSection("BillingSettings"));
// Stripe Billing
StripeConfiguration.SetApiKey(globalSettings.StripeApiKey);
// Repositories
services.AddSqlServerRepositories(globalSettings);
2017-04-27 14:17:04 +02:00
// Context
services.AddScoped<CurrentContext>();
2017-09-07 23:04:55 +02:00
// Identity
2018-04-17 06:36:30 +02:00
services.AddCustomIdentityServices(globalSettings);
//services.AddPasswordlessIdentityServices<ReadOnlyDatabaseIdentityUserStore>(globalSettings);
2017-09-07 23:04:55 +02:00
// Services
services.AddBaseServices();
2017-08-07 22:31:00 +02:00
services.AddDefaultServices(globalSettings);
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
// Mvc
2017-09-08 17:41:38 +02:00
services.AddMvc(config =>
{
2018-03-21 19:26:49 +01:00
config.Filters.Add(new LoggingExceptionHandlerFilterAttribute());
2017-09-08 17:41:38 +02:00
});
2018-03-20 20:00:56 +01:00
services.Configure<RouteOptions>(options => options.LowercaseUrls = true);
// Jobs service
Jobs.JobsHostedService.AddJobsServices(services);
services.AddHostedService<Jobs.JobsHostedService>();
2017-03-18 23:52:44 +01:00
}
public void Configure(
IApplicationBuilder app,
IHostingEnvironment env,
IApplicationLifetime appLifetime,
GlobalSettings globalSettings,
ILoggerFactory loggerFactory)
2017-03-18 23:52:44 +01:00
{
loggerFactory.AddSerilog(app, env, appLifetime, globalSettings, (e) =>
{
var context = e.Properties["SourceContext"].ToString();
if(e.Level == LogEventLevel.Information &&
(context.StartsWith("\"Bit.Billing.Jobs") || context.StartsWith("\"Bit.Core.Jobs")))
{
return true;
}
return e.Level >= LogEventLevel.Error;
});
2017-03-18 23:52:44 +01:00
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
2018-03-20 20:00:56 +01:00
app.UseAuthentication();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
2017-03-18 23:52:44 +01:00
}
}
}