2015-08-08 45 views
-3

我有一個3層應用程序,圖層爲:
Web:表示層(ASP.NET MVC) - >僅希望看到服務層 BLL:服務層 - >僅看到DAL DAL:數據訪問層 - >握住我的EDMX
IAM使用下面的工作單位和存儲庫:從web項目中刪除dal引用

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>()); } 
       } 

和Web應用程序,我想不使用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); 
       } 
+0

有人說_infinite monkeys_?我認爲他們剛剛在哈姆雷特工作 – MickyD

+0

:你可以要求更多的信息! – samir448

回答

1

有爲什麼要隱藏你的域模型以及從表現層的DAL理由嗎?除非你有充足的理由,否則你最好保持簡單並公開它。您仍然可以使用視圖模型來避免在您的視圖中使用您的EF實體(並通過僅將您需要的屬性投影到您的視圖模型中來提高查詢效率)

我不知道爲什麼大家都想實現它們自己的工作單位和存儲庫。 EF上下文已經是工作單元和存儲庫!