问题描述
如果在presentation层只应该使用服务的话,那么服务类必须公开那些已经由库实现了相同的方法,只是为了让他们提供给presentation层。
If the presentation layer is only supposed to use services then, then service classes must expose the same methods that are already implemented by repositories just to make them available to the presentation layer.
这似乎是错误的。有人能澄清一下吗?
This seems wrong. Can someone clarify it for me?
推荐答案
我的赌注是,它似乎错了,因为你实际上并不需要这种级别的抽象。
My bet is that it seems wrong because You don't actually need this level of abstraction.
应用服务。坏的门面是一个增加了更多比它解决的复杂性。事情是这样的:
Application services are facades. Bad facade is one that adds more complexity than it resolves. Something like this:
public int Increment(int v){ v=v+1;return v;}
除非它解决复杂或不够明确你想要的一切,以便客户脱钩尽可能多地通过附加层 - 这是没用的。
Unless it resolves complexity enough or You explicitly want everything to go through additional layer in order to decouple client as much as possible - it's useless.
个人而言,我只是坚持在控制这些东西(如果使用MVC模式):
Personally, I would just stick these things in controller (if MVC pattern is used):
public ActionResult ViewBlogPost(int id){
//I like to name repositories as collections
var blog=_blogs.Find(id);
blog.IsBeingViewedBy(_currentViewer);
return View(blog);
}
这篇关于在DDD可在presentation层同时使用存储库和服务类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!