-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
feat: add DbContext factory support (#49) #57
base: master
Are you sure you want to change the base?
feat: add DbContext factory support (#49) #57
Conversation
Hi @TanvirArjel, Please take a look at my pull request when you have some free time. Best Regards, |
// For multiple DbContext | ||
services.AddQueryRepository<YourDbContext1>(); | ||
services.AddQueryRepository<YourDbContext2>(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmitrii-kiselev I am still not sure about why services.AddQueryRepository<YourDbContext1>();
will not work worked in Blazor but services.AddQueryRepositoryFactory<YourDbContext>();
will work. Could you please provide a runnable blazor demo app where services.AddQueryRepository<YourDbContext1>();
is not working and that's why we need to use services.AddQueryRepositoryFactory<YourDbContext>();
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @TanvirArjel,
Thank you for your feedback.
I will prepare a detailed example for you.
For now, I will attach a brief description:
https://learn.microsoft.com/en-us/ef/core/dbcontext-configuration/#using-a-dbcontext-factory-eg-for-blazor
Since the Repository<TDbContext>
and QueryRepository<TDbContext>
classes are internal, there is currently no way to create multiple parallel repositories with independent DbContext
.
EF Core doesn't support multiple parallel operations being run on the same context instance. You should always wait for an operation to complete before beginning the next operation. This is typically done by using the await keyword on each async operation.
https://learn.microsoft.com/en-us/ef/core/miscellaneous/async
We can experiment with dependency injection using a Transient
lifetime.
We can use IDbContextFactory<TDbContext>
, but the created context instance cannot be integrated into the repository due to implementation scope.
Even by making the Repository<TDbContext>
and QueryRepository<TDbContext>
classes public, we will have to create our factory to follow the clean architecture, so it is better to implement this in the library.
So the best option is a factory that allows us to create transient instances and destroy them by using
statement.
Best Regards,
Dmitrii Kiselev
Closes #49