从web项目中删除所有引用

本文关键字:引用 删除 web 项目 | 更新日期: 2023-09-27 18:06:55

我有一个三层应用程序,图层是:
Web:表示层. NET MVC) -->希望只看到服务层服务层——>只看到DALDAL:数据访问层-> Hold my Edmx
我使用的工作单元和存储库如下:

    public interface IUnitOfWo
            {
                IGenericRepo<Actor,ActorDto> ActorRepo{ get; }
                void Save();
            }

这是IUnitOfWork的实现

    public IGenericRepo<Actor, ActorDto> ActorRepo
                {
                    get { return actorRepo ??(actorRepo = new GenericRepo<NtierMvcAppEntities, Actor, ActorDto>()); }
                }

和WebApp我想获取数据这样不使用DAL:

     private IUnitOfWo _unitOfWork;
                public TestController(IUnitOfWo unitOfWork)
                {
                    _unitOfWork = unitOfWork;
                }
                       public ActionResult Index()
                {
                    // get all models
                    List<ActorDto> modelList = _unitOfWork.ActorRepo.GetAll();
                    //  this line wont work without have reference of DAL.dll
                    return View(modelList);
                }

从web项目中删除所有引用

您想要从表示层隐藏域模型和DAL的原因是什么?

除非你有很好的理由,否则你最好保持简单并公开它。您仍然可以使用视图模型来避免在视图中使用EF实体(并且通过仅将您需要的属性投影到视图模型中来进行更有效的查询)

我不知道为什么每个人都想实现他们自己的工作单元和存储库。EF上下文已经是一个工作单元和一个存储库!