ffernandolima / ef-core-data-access

It's a modern and generic data access structure for .NET and Microsoft.EntityFrameworkCore. It supports UnitOfWork, Repository and QueryBuilder patterns. It also includes auto history utilities, multiple databases support with distributed transactions and databases/tables sharding for some database providers.
MIT License
165 stars 25 forks source link

add IServiceProvider to the constructor to generate parameters by Dep… #5

Closed juanitoDruort closed 3 years ago

juanitoDruort commented 3 years ago

…endency injection for the CustomRepository method And Test Ef 5

ffernandolima commented 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.

juanitoDruort commented 3 years ago

Thank you

ffernandolima commented 3 years ago

Closing this PR since the implementation is already covered.