public static void AddDatabaseRegistration(this IServiceCollection services, EmployerDemandConfiguration config, string environmentName) { if (environmentName.Equals("DEV", StringComparison.CurrentCultureIgnoreCase)) { services.AddDbContext <EmployerDemandDataContext>(options => options.UseInMemoryDatabase("SFA.DAS.EmployerDemand"), ServiceLifetime.Transient); } else if (environmentName.Equals("LOCAL", StringComparison.CurrentCultureIgnoreCase)) { services.AddDbContext <EmployerDemandDataContext>(options => options.UseSqlServer(config.ConnectionString).EnableSensitiveDataLogging(), ServiceLifetime.Transient); } else { services.AddSingleton(new AzureServiceTokenProvider()); services.AddDbContext <EmployerDemandDataContext>(ServiceLifetime.Transient); } services.AddTransient <IEmployerDemandDataContext, EmployerDemandDataContext>(provider => provider.GetService <EmployerDemandDataContext>()); services.AddTransient(provider => new Lazy <EmployerDemandDataContext>(provider.GetService <EmployerDemandDataContext>())); }
public EmployerDemandDataContext(IOptions <EmployerDemandConfiguration> config, DbContextOptions <EmployerDemandDataContext> options, AzureServiceTokenProvider azureServiceTokenProvider) : base(options) { _configuration = config.Value; _azureServiceTokenProvider = azureServiceTokenProvider; }