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