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;
|
2017-03-18 23:52:44 +01:00
|
|
|
|
|
|
|
|
|
namespace Bit.Billing
|
|
|
|
|
{
|
|
|
|
|
public class Startup
|
|
|
|
|
{
|
|
|
|
|
public Startup(IHostingEnvironment env)
|
|
|
|
|
{
|
|
|
|
|
var builder = new ConfigurationBuilder()
|
2017-05-06 05:03:03 +02:00
|
|
|
|
.AddSettingsConfiguration(env, "bitwarden-Billing");
|
2017-03-18 23:52:44 +01:00
|
|
|
|
Configuration = builder.Build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IConfigurationRoot Configuration { get; }
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
services.AddSqlServerRepositories();
|
|
|
|
|
|
2017-04-27 14:17:04 +02:00
|
|
|
|
// Context
|
|
|
|
|
services.AddScoped<CurrentContext>();
|
|
|
|
|
|
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-03-18 23:52:44 +01:00
|
|
|
|
services.AddMvc();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2017-05-06 02:57:33 +02:00
|
|
|
|
loggerFactory
|
|
|
|
|
.AddSerilog(env, appLifetime, globalSettings, (e) => e.Level >= LogEventLevel.Error)
|
|
|
|
|
.AddConsole()
|
|
|
|
|
.AddDebug();
|
2017-03-18 23:52:44 +01:00
|
|
|
|
|
2017-05-08 18:34:53 +02:00
|
|
|
|
if(env.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-25 14:57:43 +02:00
|
|
|
|
// Default Middleware
|
|
|
|
|
app.UseDefaultMiddleware(env);
|
2017-07-21 18:53:26 +02:00
|
|
|
|
|
2017-03-18 23:52:44 +01:00
|
|
|
|
app.UseMvc();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|