2
私はASP.NET Coreアプリケーションで一般的なDIの使用法を使用しています。 ConfigContext
でASP.NETコアの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));
}
UserContext
にconnectionString
を返すメソッドGetUserString
が存在します。 UserContext
にお申込みの場合、AddScoped UserContext
とconnectionString
とConfigContext
が必要です。
接続文字列はリクエストごとに異なる場合があります(別のユーザー)。 –
はい、configcontextのロジックによって異なる場合があります –