diff --git a/src/Api/Startup.cs b/src/Api/Startup.cs index b4d99a3c42..611e601860 100644 --- a/src/Api/Startup.cs +++ b/src/Api/Startup.cs @@ -13,9 +13,6 @@ using Bit.Api.Utilities; using Bit.Core; using Bit.Core.Models.Table; using Bit.Core.Identity; -using Bit.Core.Repositories; -using Bit.Core.Services; -using SqlServerRepos = Bit.Core.Repositories.SqlServer; using System.Text; using System.Linq; using Microsoft.AspNetCore.Mvc.Formatters; @@ -88,16 +85,7 @@ namespace Bit.Api StripeConfiguration.SetApiKey(globalSettings.StripeApiKey); // Repositories - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); + services.AddSqlServerRepositories(); // Context services.AddScoped(); @@ -195,14 +183,8 @@ namespace Bit.Api services.AddScoped(); // Services - services.AddSingleton(); - services.AddSingleton(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); + services.AddBaseServices(); + services.AddDefaultServices(); // Cors services.AddCors(config => diff --git a/src/Billing/Startup.cs b/src/Billing/Startup.cs index def0594a94..ec4cefe40b 100644 --- a/src/Billing/Startup.cs +++ b/src/Billing/Startup.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Bit.Core; +using Stripe; namespace Bit.Billing { @@ -38,11 +39,22 @@ namespace Bit.Billing services.AddOptions(); // Settings - //var globalSettings = new GlobalSettings(); - //ConfigurationBinder.Bind(Configuration.GetSection("GlobalSettings"), globalSettings); - //services.AddSingleton(s => globalSettings); + var globalSettings = new GlobalSettings(); + ConfigurationBinder.Bind(Configuration.GetSection("GlobalSettings"), globalSettings); + services.AddSingleton(s => globalSettings); services.Configure(Configuration.GetSection("BillingSettings")); + // Stripe Billing + StripeConfiguration.SetApiKey(globalSettings.StripeApiKey); + + // Repositories + services.AddSqlServerRepositories(); + + // Services + services.AddBaseServices(); + services.AddDefaultServices(); + + // Mvc services.AddMvc(); } diff --git a/src/Core/ServiceCollectionExtensions.cs b/src/Core/ServiceCollectionExtensions.cs new file mode 100644 index 0000000000..4b67bbb23d --- /dev/null +++ b/src/Core/ServiceCollectionExtensions.cs @@ -0,0 +1,47 @@ +using Bit.Core.Repositories; +using Bit.Core.Services; +using Microsoft.Extensions.DependencyInjection; +using SqlServerRepos = Bit.Core.Repositories.SqlServer; + +namespace Bit.Core +{ + public static class ServiceCollectionExtensions + { + public static void AddSqlServerRepositories(this IServiceCollection services) + { + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + } + + public static void AddBaseServices(this IServiceCollection services) + { + services.AddSingleton(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + } + + public static void AddDefaultServices(this IServiceCollection services) + { + services.AddSingleton(); + services.AddScoped(); + services.AddScoped(); + } + + public static void AddNoopServices(this IServiceCollection services) + { + services.AddSingleton(); + services.AddScoped(); + services.AddScoped(); + } + } +}