在Connection类中
public Connection(IConfiguration _Configuration)
{
dbConnectionString = _Configuration.GetConnectionString("DefaultConnection");
}
在“配置方法”的“启动”类中
services.AddDbContext<Models.AwardContext>(option =>
option.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
答案 0 :(得分:0)
您首先应该在Configuration
中将Singleton
添加为ConfigureServices
:
services.AddSingleton(_ => Configuration);