.NET MAUI AddDbContext 与依赖注入

问题描述 投票:0回答:0

我在 .Net MAUI 中有一个应用程序,我想知道是否可以通过依赖注入,以某种方式执行 services.AddDbContext。我希望清楚

我的代码:

public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration)
{
    services.AddDbContext<StoreCustomersContext>(opt =>
    {
        connectionString = configurations.GetConnectionString("DefaultConnection");
    });
}

错误:

Severity Code Description Project File Line Status Deleted
     Error CS1061 "IServiceCollection" does not contain a definition for "AddDbContext" or an accessible extension method "AddDbContext" that accepts a first argument of type "IServiceCollection" (are you missing a using directive or an assembly reference?)

谢谢

c# .net entity-framework maui
© www.soinside.com 2019 - 2024. All rights reserved.