vany0114 / EF.DbContextFactory

With EF.DbContextFactory you can resolve easily your DbContext dependencies in a safe way injecting a factory instead of an instance itself, enabling you to work in multi-thread contexts with Entity Framework or just work safest with DbContext following the Microsoft recommendations about the DbContext lifetime.
http://elvanydev.com/EF-DbContextFactory/
MIT License
93 stars 21 forks source link

Allow a DbContext to have a derived service implementation registered #28

Open Meberem opened 4 years ago

Meberem commented 4 years ago

AddAppDbContext in ef core has an overload allowing a developer to specify a "Service Type" and an "Implementation Type" for a DbContext. This allows you to have a base type in a Domain project and a particular implementation in a different project. This pull request is based on the ef core code here: https://github.com/dotnet/efcore/blob/c69926a8cdd05f4427e89ac8bac734e490b3d23a/src/EFCore/Extensions/EntityFrameworkServiceCollectionExtensions.cs#L351

The result is that I can now do this in my Startup.cs

services.AddDbContextFactory<AppDbContext, SqlServerAppDbContext>();

I don't know what you would like to do about Tests for this, as I didn't want to disrupt the existing setup.

vany0114 commented 4 years ago

Hi @Meberem thanks for taking the time to do this! I've been very busy, so I'll try to take a look in the coming weeks, sorry about it.

Meberem commented 4 years ago

Hey @vany0114, do you think you'll have a chance to look at this any time soon?