且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在DDD可在presentation层同时使用存储库和服务类?

更新时间:2023-02-13 15:41:20

我的赌注是,它似乎错了,因为你实际上并不需要这种级别的抽象。

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