Hi,
I managed to accomplish the connection change. However, we are using a distributed cache for the entities within the "RealDataDb" context. Is there a way to reset the distributed cache for those entities, or remove them from the cache? Also, I noticed that this method gets called pretty frequently, is that expected?
Hi,
I have created a CustomConnectionStringResolver as you suggested, but now I have a follow-up question. The Default connection is stored in the host database for each tenant. However, the connection I am trying to overwrite is stored in appsettings.json, not in the host database. When I debug into the ResolveAsync method of my CustomConnectionStringResolver, it doesn't seem to find the connection I am looking for. Here is my updated ResolveAsync method:
public override async Task<string> ResolveAsync(string connectionStringName = null)
{
if (_currentUser.IsAuthenticated && _currentTenant.Id != null)
{
var useDemo = await _settingManager.GetOrNullForCurrentTenantAsync(AppSettings.UseDemo);
if (useDemo?.Equals("True", StringComparison.OrdinalIgnoreCase) == true
&& connectionStringName != null
&& connectionStringName == "RealDataDb")
{
var connectionString = _configuration.GetConnectionString("DemoDb");
if (!connectionString.IsNullOrWhiteSpace())
{
return connectionString;
}
}
}
return await base.ResolveAsync(connectionStringName);
}
Both "RealDataDb" and "DemoDb" connection strings are stored in appsettings.json. Can I still use this method to decide which connection to use depending on the value of the useDemo setting?
Hello,
I created a setting to determine whether the tenant should use a specific connection string to a database with real data or another connection string that points to a "demo" database. I followed the idea of overwriting the connection string by calling a method under ConfigureServices in our web application module as suggested by the following link: https://docs.abp.io/en/abp/6.0/Connection-Strings However, if I try to get the ISettingsManager at that point, it is always null. I have also tried getting IServiceProvider and ServiceProvider with the same unsuccessful results. Here is the method I am using to accomplish this task:
private async Task ConfigureDemo(ServiceConfigurationContext context, IConfiguration configuration)
{
var settingProvider = context.Services.GetObjectOrNull<ISettingManager>();
if (settingProvider != null)
{
var useDemoDb = await settingProvider.GetOrNullForCurrentTenantAsync(<Our_App>Settings.UseDemo);
if (useDemoDb.Equals("True", StringComparison.OrdinalIgnoreCase))
{
Configure<AbpDbConnectionOptions>(options =>
{
options.ConnectionStrings["RealDataDb"] = configuration.GetConnectionString("DemoDb");
});
}
}
}
Do you have any ideas or suggestions on how we can solve this problem? Thanks in advance!