4 Answer(s)
-
0
The abp framework will automatically use the corresponding connection string to create a DbContext based on the tenant information of the current context.
You can look at this example, please share some of your code if you can. I want to see your use case. https://github.com/aspnetboilerplate/aspnetboilerplate-samples/tree/master/MultipleDbContextEfCoreDemo
-
0
i see the demo .. here is my code
public class DbPerTenantConnectionStringResolver : DefaultConnectionStringResolver { private readonly ICurrentUnitOfWorkProvider _currentUnitOfWorkProvider; private readonly IConfigurationRoot _appConfiguration; private readonly IDBPerTenantAppService _IDBPerTenantAppService; public IAbpSession AbpSession { get; set; } public DbPerTenantConnectionStringResolver(ICurrentUnitOfWorkProvider currentUnitOfWorkProvider, IDBPerTenantAppService iDBPerTenantAppService, IAbpStartupConfiguration configuration, IHostingEnvironment hostingEnvironment) : base(configuration) { _currentUnitOfWorkProvider = currentUnitOfWorkProvider; _IDBPerTenantAppService = iDBPerTenantAppService; AbpSession = NullAbpSession.Instance; _appConfiguration = AppConfigurations.Get(hostingEnvironment.ContentRootPath, hostingEnvironment.EnvironmentName); } public override string GetNameOrConnectionString(ConnectionStringResolveArgs args) { if (args["DbContextConcreteType"] as Type == typeof(INVDbContext)) { var connctions = _IDBPerTenantAppService.GetAllConnections((int)GetCurrentTenantId(), "INV"); return connctions.Result.Items[0].VConnectionString; //_appConfiguration.GetConnectionString(ERPConsts.SecondDbConnectionStringName); } return base.GetNameOrConnectionString(args); } protected virtual int? GetCurrentTenantId() { return _currentUnitOfWorkProvider.Current != null ? _currentUnitOfWorkProvider.Current.GetTenantId() : AbpSession.TenantId; } }
i have seperate databases for according to module (InventoryDb, PayrolDb, FinanceDb) and im getting the connectionstring from database table(abpConnection) . it works good. @maliming see the code for better suggestion.
-
0
Hi @CNS
Can we close this issue ? Is your problem solved ?
-
0
This issue is closed because it has not had recent activity for a long time.