我有一個ConfigurationDbContext
,我正在嘗試使用。它有多個參數,DbContextOptions
和ConfigurationStoreOptions
。ASP.NET Core DbContext注入
如何將此DbContext添加到ASP.NET Core中的服務中?
我試圖在我的Startup.cs如下:
ConfigureServices
....
services.AddDbContext<ConfigurationDbContext>(BuildDbContext(connString));
....
private ConfigurationDbContext BuildDbContext(string connString)
{
var builder = new DbContextOptionsBuilder<ConfigurationDbContext>();
builder.UseSqlServer(connString);
var options = builder.Options;
return new ConfigurationDbContext(options, new ConfigurationStoreOptions());
}
你使用mssql服務器 – hasan
是的。但是,要構建dbcontext,我需要傳遞另一個參數。 – blgrnboy
我還添加了示例鏈接 – hasan