如果表示层只应该使用服务,那么服务类必须公开存储库已实现的相同方法,以使它们可供表示层使用。
这似乎是错误的。有人可以帮我解释一下吗?
最佳答案
我敢打赌,这似乎是错误的,因为您实际上并不需要这种抽象级别。
申请服务为facades 。糟糕的外观会增加比其解决的问题更多的复杂性。像这样的事情:
public int Increment(int v){ v=v+1;return v;}
除非它足够解决复杂性,或者您明确希望所有内容都经过附加层以尽可能地解耦客户端 - 这是没有用的。
就我个人而言,我只是将这些东西放在 Controller 中(如果使用 MVC 模式):
public ActionResult ViewBlogPost(int id){
//I like to name repositories as collections
var blog=_blogs.Find(id);
blog.IsBeingViewedBy(_currentViewer);
return View(blog);
}
关于web-applications - 在 DDD 中,表示层可以同时使用 Repository 和 Service 类吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4573857/