我一直在閱讀并且最好在我的 EF Core 專案中使用 AddScoped 以便我可以使用許多背景關系進行更新,因此我可以在執行 SaveChanges 時停止“已跟蹤”錯誤訊息。
這是我的依賴注入代碼。只是徘徊如何使這個“AddScoped”而不是 Singleton ?
任何幫助都會很棒,因為我對這種依賴注入、EF Core 等還很陌生。
public override void Configure(IFunctionsHostBuilder builder)
{
// CCT database
builder.Services.AddDbContext<sqldbCCTUKSATPPreProdContext>(
options =>
{
const string ConnString = "SQLConnectionStringCCT";
options.UseSqlServer(Configuration.GetConnectionString(ConnString)).UseQueryTrackingBehavior(QueryTrackingBehavior.TrackAll);
});
// CL database (Segimport DB)
builder.Services.AddDbContext<sqldbCLSegImportUKSATPPreProdContext>(
options =>
{
const string CLConnString = "SQLConnectionStringCL";
options.UseSqlServer(Configuration.GetConnectionString(CLConnString)).UseQueryTrackingBehavior(QueryTrackingBehavior.TrackAll);
options.EnableSensitiveDataLogging();
});
uj5u.com熱心網友回復:
AddDbContext 將背景關系注冊為默認范圍 - 請參閱其默認值contextLifetime是ServiceLifetime.Scoped. 您的“已跟蹤”問題來自其他地方。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/337229.html
上一篇:嘗試使用Google.Apis.Gmail從asp.netcorewebapi應用程式從google作業區發送電子郵件時出錯
