public void ConfigureServices(IServiceCollection services) { services.AddSingleton(Configuration); services.AddApplicationInsightsTelemetry(Configuration); services.AddMvc() .AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); options.SerializerSettings.Converters.Add(new SwpDateTimeConverter()); }); if (_env.IsDevelopment()) { services.AddTransient <IMailService, DevMailService>(); services.AddSingleton(ConnectionStringManager.Create( (type) => { switch (type == null ? "" : type.ToLower()) { case "mysql": return(DevSecrets.GetSecretValue("connectionStrings:findme:mysql")); default: return(DevSecrets.GetSecretValue("connectionStrings:findme:mssql")); } })); } else { services.AddTransient <IMailService, MailService>(); if (this.Configuration.IsPublishEnvStaging()) { services.AddSingleton(ConnectionStringManager.Create( (type) => { switch (type == null ? "" : type.ToLower()) { case "mysql": return(Configuration["ConnectionStrings:staging:MySqlConnection"]); default: return(Configuration["ConnectionStrings:staging:MsSqlConnection"]); } })); } else { services.AddSingleton(ConnectionStringManager.Create( (type) => { switch (type == null ? "" : type.ToLower()) { case "mysql": return(Configuration["ConnectionStrings:production:MySqlConnection"]); default: return(Configuration["ConnectionStrings:production:MsSqlConnection"]); } })); } } services.AddDbContext <AppDbContext>(); services.AddSingleton <WebDbRepository>(); services.AddTransient <AppMigrationSeedManager>(); }
public AppDbContext(ConnectionStringManager connStrMngr, DbContextOptions options) : base(connStrMngr == null ? null : connStrMngr.GetConnectionString, options) { }