entity-framework-6 - 部分服务无法构建dbcontext
问题描述
我正在从 asp.net 项目迁移一个 asp.net core 3.1。在这里,我有一个 dbcontext,我需要从我的 appservice 类之一传递连接字符串。要使用 appservice,在这个 dbcontext 中我使用了如下内容:
public class MyContext: DbContext
{
private readonly IAppSetting _appSetting;
public MyContext(IAppSetting appSetting)
{
_appSetting = appSetting;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(_appSetting.Myconnectionstring, opts=> opts.CommandTimeout((int)TimeSpan.FromMinutes(1).TotalSeconds));
}
}
在 StartUp.cs 文件中,我配置了这个上下文服务,如下所示:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<MyContext>();
}
但是当我运行应用程序时,它会抛出运行时错误,例如:
某些服务无法构造 dbcontext。
请帮忙。
解决方案
推荐阅读
- java - android.widget.Spinner.setAdapter(android.widget.SpinnerAdapter) 在空对象引用上
- vb.net - VB.NET 在子例程的参数中使用“New”语句创建的资源范围
- laravel - Laravel:如何在 where 条件下获取一组记录中的最新记录?
- python-3.x - 如何查看您授权的 AWS Lambda 函数列表
- mysql - 显示客户每天的花费以及他们是否在前一天花费过 (SQL)
- css - 行列之间的间距
- azure-ad-b2c - AADB2C: 请求 URI ' ' 解析为受限 IP 范围内的 IP 地址
- java - Java 子类化:覆盖和创建新方法
- ruby-on-rails - RAILS_ENV=生产轨道资产:预编译不适用于 RSpec
- node.js - 如何将数组发送到 mongodb 地图集?