C# 从web项目中删除dal引用
我有一个3层应用程序,层是:C# 从web项目中删除dal引用,c#,asp.net,C#,Asp.net,我有一个3层应用程序,层是: Web:表示层(ASP.NET MVC)-->只想查看服务层 BLL:服务层-->仅查看DAL DAL:数据访问层-->保持我的Edmx iam使用工作单元和存储库,如下所示: public interface IUnitOfWo { IGenericRepo<Actor,ActorDto> ActorRepo{ get; } void Save();
Web:表示层(ASP.NET MVC)-->只想查看服务层 BLL:服务层-->仅查看DAL DAL:数据访问层-->保持我的Edmx
iam使用工作单元和存储库,如下所示:
public interface IUnitOfWo
{
IGenericRepo<Actor,ActorDto> ActorRepo{ get; }
void Save();
}
公共接口iunitofo
{
IGenericRepo ActorRepo{get;}
作废保存();
}
下面是IUnitOfWork的实现
public IGenericRepo<Actor, ActorDto> ActorRepo
{
get { return actorRepo ??(actorRepo = new GenericRepo<NtierMvcAppEntities, Actor, ActorDto>()); }
}
public IGenericRepo ActorRepo
{
获取{return actorRepo???(actorRepo=new GenericRepo());}
}
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);
}
private IUnitOfWo\u unitOfWork;
公共测试控制器(IUnitOfWo unitOfWork)
{
_unitOfWork=unitOfWork;
}
公共行动结果索引()
{
//获取所有模型
List modelList=_unitOfWork.ActorRepo.GetAll();
//如果没有DAL.dll的引用,此行将无法工作
返回视图(模型列表);
}
您想在表示层中隐藏域模型和DAL的原因是什么
除非你有充分的理由,否则你最好保持它的简单并公开它。您仍然可以使用视图模型,以避免在视图中使用EF实体(并通过仅将所需的特性投影到视图模型中来进行更高效的查询)
我不知道为什么每个人都想实现自己的工作单元和存储库。EF上下文已经是工作单元和存储库了 有人说无限猴子吗?我想他们正在研究《哈姆雷特》:你可以问更多的信息!!