Closed juanitoDruort closed 3 years ago
It's already supported by the library @juanitoDruort.
EF Core has an internal IServiceProvider
which can be accessed through DbContext.GetInfrastructure()
with the main purpose of resolving services directly using the service locator pattern.
The library checks if any repository (custom or generic) has been registered into the MS Built-In container and also tries to resolve it from there (it's going to resolve any registered dependency as well), in case the repository hasn't been registered it uses the internal factory in order to instantiate the repository. This behavior can be found here and here.
The library also counts on some extensions to help developers registering repositories. The extensions can be found here and here.
If you just want to have access to IServiceProvider
from your UnitOfWork
instance, you can use _unitOfWork.DbContext.GetInfrastructure()
and then use .GetService<T>()
or .GetRequiredService<T>()
to resolve any service you need to. The same can be done inside custom repository instances.
I appreciate the time you've spent on this feature, but unfortunately, it's already covered.
Thank you
Closing this PR since the implementation is already covered.
…endency injection for the CustomRepository method And Test Ef 5