Зарегистрируйте EF Core с помощью IDbContextFactory в ASP.NET Core Mvc ⇐ C#
-
Anonymous
Зарегистрируйте EF Core с помощью IDbContextFactory в ASP.NET Core Mvc
I've created a project App.Data that contains domain objects and a base class that implements IDbContextFactory for creating a DbContext. The code is available here.
Generating the migrations in a seperate assembly works well.
What I would like to utilize the context I've created in App.Data.Sql that is created via an SqlDbContextFactory when registering entity framework within asp.net mvc.
What I want to have is something like
services.AddEntityFrameworkSqlServer() .AddDbContext(typeof(SqlDbContextFactory)) Registering it as a singleton doesn't work since when resolved complains about no provider has been configured.
services.AddSingleton(); services.AddScoped(p => p.GetRequiredService().Create());
Источник: https://stackoverflow.com/questions/440 ... t-core-mvc
I've created a project App.Data that contains domain objects and a base class that implements IDbContextFactory for creating a DbContext. The code is available here.
Generating the migrations in a seperate assembly works well.
What I would like to utilize the context I've created in App.Data.Sql that is created via an SqlDbContextFactory when registering entity framework within asp.net mvc.
What I want to have is something like
services.AddEntityFrameworkSqlServer() .AddDbContext(typeof(SqlDbContextFactory)) Registering it as a singleton doesn't work since when resolved complains about no provider has been configured.
services.AddSingleton(); services.AddScoped(p => p.GetRequiredService().Create());
Источник: https://stackoverflow.com/questions/440 ... t-core-mvc
Мобильная версия