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

104 lines
3.3 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);
// PayPal Clients
2019-02-02 04:25:34 +01:00
services.AddSingleton<Utilities.PayPalClient>();
services.AddSingleton<Utilities.PayPalIpnClient>();
2019-02-01 23:16:28 +01:00
2019-02-22 04:43:37 +01:00
// BitPay Client
services.AddSingleton<BitPayClient>();
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, uncomment when we have some jobs to run
// 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;
}
2019-02-23 04:55:40 +01:00
return e.Level >= LogEventLevel.Warning;
});
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
}
}
}