-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add EfCoreTransactionStrategy to share transactions #1834
Conversation
Thanks a lot. I will review it. |
Thank you very much. It's well designed. I merged and will be released with v1.5.0. I will continue to review it and will refactor if needed. |
I will make a few changes if it works: #1909 |
So, it's better to check ExistingConnection before (renamed from Connection): Configuration.Modules.AbpEfCore().AddDbContext<MyDbContext>(options =>
{
if (options.ExistingConnection != null)
{
options.DbContextOptions.UseSqlServer(options.ExistingConnection);
}
else
{
options.DbContextOptions.UseSqlServer(options.ConnectionString);
}
}); |
@hikalkan One thing with given solution is : options.DbContextOptions.UseSqlServer(options.ConnectionString); Always return the "Default" conn string. Is there any way to register my custom dbcontext conn string different from Default ? Right now I am using the following approach: IHostingEnvironment env = IocManager.Resolve<IHostingEnvironment>();
var connString = env.GetAppConfiguration().GetConnectionString(BusinessIntelligenceConsts.ConnectionStringName);
BusinessIntelligenceDbContextConfigurer.Configure(configuration.DbContextOptions, connString); And now i will try to apply the given solution and try to resolve #2325 |
See https://aspnetboilerplate.com/Pages/Documents/Entity-Framework-Core:
|
@acjh This will work for main app conn string. I have 5 modules each with its own conn string. Or are you suggesting extending the configuration for each module ? |
You should implement and replace IConnectionStringResolver. In this custom service you can check dbcontext type (or other logic) to determine connection string dynamically. DbPerTenantConnectionStringResolver (https://github.com/aspnetboilerplate/module-zero/blob/dev/src/Abp.ZeroCore.EntityFrameworkCore/Zero/EntityFrameworkCore/DbPerTenantConnectionStringResolver.cs) changes it to dynamically determine connection string per tenant. |
Hi @hikalkan,
I've implemented the EfCoreTransactionStrategy based on EfTransactionStrategy. It fix #1829.
One thing I don't know if it's good enough: The connection is propagated through AbpDbContextConfiguration. At Startup we should do the following:
The Configure method should have an overload for DbConnection:
I'll appreciate your review. Thank you!
P.S.: I would like to thank @alexandrejose for the collaboration in the development! :)