首页 > 解决方案 > 尝试激活“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;
        }
    }

标签: c#asp.net-core

解决方案


问题是因为您正在为 IRepoBLL 解析服务,但您尚未在 Startup.cs 中注册 IRepoDLL。IRepoDLL 服务未注入 BLL 代码public RepoBll(IRepoDll _orepo)。将此添加到 Startup.csservices.AddScoped<IRepoDll, RepoDll>();并且应该可以工作。


推荐阅读