We must use Azure Key Vault to store all secrets, including our connection strings.
I changed the CustomsEntityFrameworkCoreModule PreInitialize method to look like such:
public override void PreInitialize()
{
var connectionString = _appConfig["db-dev"];
Configuration.DefaultNameOrConnectionString = connectionString;
if (!SkipDbContextRegistration)
{
Configuration.Modules.AbpEfCore().AddDbContext<CustomsDbContext>(configuration =>
{
CustomsDbContextConfigurer.Configure(configuration.DbContextOptions, connectionString);
});
}
}
This works locally, but breaks in a hosted environment.
How can I replace the DefaultConnectionStringResolver?
3 Answer(s)
-
0
Hi,
You can use ReplaceService method in your module's PreInitialize method.
Configuration.ReplaceService<IConnectionStringResolver, MyConnectionStringResolver>(DependencyLifeStyle..Transient);
Thanks.
-
0
Thanks for the response!
I am curious, what I actually did was this:
services.AddSingleton<IConnectionStringResolver, AzureKeyVaultConnectionStringResolver>();
in my startup.cs.
Is your method preferable? It seems your approach will override only for that module, but I don't know what modules embedded in ABP will be relying on a connection string?
-
0
Hi @strix20,
If a module calls ReplaceService in it's PreInitialize other than your module, the last one replaces the old ones. So, you should consider it with this information.
Thanks.