2
在我的ASP.NET Core应用程序中有常见的DI用法。在ASP.NET Core中使用DI初始化初始化对象的对象
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped(sp => new UserContext(new DbContextOptionsBuilder().UseNpgsql(configuration["User"]).Options));
services.AddScoped(sp => new ConfigContext(new DbContextOptionsBuilder().UseNpgsql(configuration["Config"]).Options));
}
在ConfigContext
存在方法GetUserString
它返回到connectionString
UserContext
。 而我需要AddScoped UserContext
与connectionString
从ConfigContext
当适用于UserContext
时。
连接字符串可以根据每个请求(不同的用户)而变化吗? –
是的,可以根据configcontext中的逻辑而有所不同 –