Topic: How to force DI to use request specific version of assembly for DbContext instance creation ? Is it possible to create custom scoped service factory or use some other DI library ?
How to force DI to use request specific version of assembly for DbContext instance creation ?
Is it possible to create custom scoped service factory or use some other DI library ?
It looks like .NET 5 loads DbContext.dll on first use and does not allow to use different versions. This is ASP.NET 5 MVC Core application using EF Core with Npgsql data provider.
Author: TEJA
PARTH
You can create a custom scoped service factory to solve your purpose.
SAI
Instead of injecting a dbcontext instance, you should inject a factory. The factory could be as simple as a dictionary of dbcontext s keyed by a version identifier.
Note: unless your versions implemented a common interfaces you will need to use reflection to call the methods.