How to dynamic modify the DbContext's ConnectionString in AppService?
See original GitHub issue- Abp package version:4.10.1.
- base framework: .Net Core.
I need to connect to multiple external databases of ERP in Abp Modular. My method is dynamic modify the DbContext’s ConnectionString in AbpController of Web Project. The code is as follows:
var connectionStringBuilder = new DbConnectionStringBuilder();
...
var db = _dbContextResolver.Resolve<MyDbContext>(connectionStringBuilder.ConnectionString, null);
(Data processing code...)
But I think the best way should be in the Application Project’s AppService. My question is: How to realize the above code functions in the AppService?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Dynamically change connection string in Asp.Net Core
I was able to change the connection string for each request by moving the connection string logic into the OnConfiguring method of the...
Read more >Configuring Entity Framework Core with Dynamic Connection ...
We need to handle dynamic connection strings. The idea is that different clients of our Web API need to have different databases.
Read more >Change Connection String at Runtime in ASP.NET CORE
C# Tutorial - Change ConnectionString at Runtime with App.config | ... Setup the DbContext Class and Database Connection String | ASP.
Read more >Change DB Context connection string dynamically in ASP. ...
I have created parameterized DBcontext with Dbconnectionstring Parameter, in this way we can pass connection string before binding Customer ...
Read more >DbContext Lifetime, Configuration, and Initialization
This example registers a DbContext subclass called ApplicationDbContext as a scoped service in the ASP.NET Core application service provider ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found the solution, same as the control. In the AppService inject IDbContextResolver, by IDbContextResolver resolver the DbContext and change it’s ConnectionString. Thanks everyone…
You can implement your own connection string resolver similar to https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.Zero.EntityFramework/Zero/EntityFramework/DbPerTenantConnectionStringResolver.cs