web-applicationsarchitecturedomain-driven-design

In DDD can the presentation layer use both the Repository and Service classes?


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?


Solution

  • 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.

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