c# - 尝试激活“BusinessAccess.Repo.RepoBll”时无法解析“DataAccesssLayer.DataLogic.IRepoDll”类型的服务
问题描述
这里我使用 N 层架构作为 DLL --->“IRepoDll,RepoDll”,
BLL-->"IRepoBll,RepoBll",
模型-->所有数据库模型,
ViewMode--->所有ViewModl,
PresentationLayer---> 这里我使用的是 WebApi
这里我的架构是 UI<=====>Bll<=====>Dll<=====>DataBase 请帮助我为什么我无法在 Ui 层 Startup.cs中访问我的 Dll
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
var connection = Configuration.GetConnectionString("DatabaseConnection");
services.AddScoped<IRepoBll, RepoBll>();
}
家庭控制器
private readonly IRepoBll Orepo;
public HomeController(IRepoBll _repo)
{
this.Orepo = _repo;
}
[HttpGet]
[Route("MyData")]
public IEnumerable<Employee> GetData()
{
var x = this.Orepo.GetEmployee();
return null;
}
代码
public class RepoBll : IRepoBll
{
private readonly IRepoDll Orepo;
public RepoBll(IRepoDll _orepo){
this.Orepo = _orepo;
}
public IEnumerable<Employee> GetEmployee()
{
var x = this.Orepo.GetCastRecords();
return null;
}
}
DLL代码
public class RepoDll : IRepoDll
{
private readonly DatabaseContext _Context;
private readonly IConfiguration _configuration;
public RepoDll(DatabaseContext _Context, IConfiguration configuration)
{
this._Context = _Context;
_configuration = configuration;
}
public IEnumerable<Tbl_Cast> GetCastRecords()
{
var x = (from n in _Context.Tbl_Cast
orderby n.Cast_Id
select n).ToList();
return x;
}
}
解决方案
问题是因为您正在为 IRepoBLL 解析服务,但您尚未在 Startup.cs 中注册 IRepoDLL。IRepoDLL 服务未注入 BLL 代码public RepoBll(IRepoDll _orepo)
。将此添加到 Startup.csservices.AddScoped<IRepoDll, RepoDll>();
并且应该可以工作。
推荐阅读
- python - 抓取由 Javascript 生成的网页
- swift - 是否可以在 Swift 中将 UILabel 或 CATextLayer 添加到 CGPath,类似于 Photoshop 的类型到路径功能?
- algorithm - 为什么 IDA* 比 A* 快,但为什么 IDA* 访问的节点比 A* 多?
- java - IntelliJ Java groovy 缺少库?
- ios - 如何使用 Realm 和 Swift 从 TableView 中删除部分和行?
- c# - 使用 XPath 向多个元素添加元素无法按预期工作
- c# - 如何获取 DB 关系的一行中的所有值并将它们中的每一个分配给 ASP.NET C# 中的变量
- c - 功能故障
- javascript - 实现搜索功能的问题“TypeError:data.filter 不是函数”
- entity-framework-core - 使用 EF Core 获取 Long 列表