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;
|
2017-04-26 20:29:25 +02:00
|
|
|
|
using Bit.Core;
|
2017-04-26 22:13:24 +02:00
|
|
|
|
using Stripe;
|
2017-05-06 02:57:33 +02:00
|
|
|
|
using Bit.Core.Utilities;
|
|
|
|
|
using Serilog.Events;
|
2017-05-08 18:34:53 +02:00
|
|
|
|
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
|
|
|
|
|
{
|
2017-10-19 06:08:09 +02:00
|
|
|
|
public Startup(IConfiguration configuration)
|
2017-03-18 23:52:44 +01:00
|
|
|
|
{
|
2017-10-19 06:08:09 +02:00
|
|
|
|
Configuration = configuration;
|
2017-03-18 23:52:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-19 06:08:09 +02:00
|
|
|
|
public IConfiguration Configuration { get; }
|
2017-03-18 23:52:44 +01:00
|
|
|
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
2017-04-26 20:29:25 +02:00
|
|
|
|
// Options
|
|
|
|
|
services.AddOptions();
|
|
|
|
|
|
|
|
|
|
// Settings
|
2017-05-06 02:57:33 +02:00
|
|
|
|
var globalSettings = services.AddGlobalSettingsServices(Configuration);
|
2017-05-06 15:15:07 +02:00
|
|
|
|
services.Configure<BillingSettings>(Configuration.GetSection("BillingSettings"));
|
2017-04-26 20:29:25 +02:00
|
|
|
|
|
2017-04-26 22:13:24 +02:00
|
|
|
|
// Stripe Billing
|
|
|
|
|
StripeConfiguration.SetApiKey(globalSettings.StripeApiKey);
|
|
|
|
|
|
|
|
|
|
// Repositories
|
2017-12-01 15:22:04 +01:00
|
|
|
|
services.AddSqlServerRepositories(globalSettings);
|
2017-04-26 22:13:24 +02:00
|
|
|
|
|
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
|
|
|
|
|
2017-04-26 22:13:24 +02:00
|
|
|
|
// Services
|
|
|
|
|
services.AddBaseServices();
|
2017-08-07 22:31:00 +02:00
|
|
|
|
services.AddDefaultServices(globalSettings);
|
2017-04-26 22:13:24 +02:00
|
|
|
|
|
2017-05-08 18:34:53 +02:00
|
|
|
|
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
|
|
|
|
2017-04-26 22:13:24 +02:00
|
|
|
|
// 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);
|
2018-08-10 17:20:04 +02:00
|
|
|
|
|
|
|
|
|
// Jobs service
|
|
|
|
|
Jobs.JobsHostedService.AddJobsServices(services);
|
|
|
|
|
services.AddHostedService<Jobs.JobsHostedService>();
|
2017-03-18 23:52:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-06 02:57:33 +02:00
|
|
|
|
public void Configure(
|
|
|
|
|
IApplicationBuilder app,
|
|
|
|
|
IHostingEnvironment env,
|
|
|
|
|
IApplicationLifetime appLifetime,
|
|
|
|
|
GlobalSettings globalSettings,
|
|
|
|
|
ILoggerFactory loggerFactory)
|
2017-03-18 23:52:44 +01:00
|
|
|
|
{
|
2018-08-10 17:20:04 +02: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
|
|
|
|
|
2017-05-08 18:34:53 +02: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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|