在.net7使用新搭建机架的项目
功能时出现这个问题:
Unable to resolve service for type ‘xxx’ while attempting to activate ‘xxx’.
解决方法
public class BZContext : DbContext
{
//在使用 新搭建机架的项目 时注释掉这个构造函数使用下面的重写方法就行了
public BZContext(DbContextOptions<BZContext> options) : base(options)
{
}
#if DEBUG
//搭建完以后注释掉这里使用上面的方式就行
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("数据库连接字符串");
}
#endif
}