在 DDD 中,表示层可以同时使用 Repository 和 Service 类吗?

编程入门 行业动态 更新时间:2024-10-24 00:21:27
本文介绍了在 DDD 中,表示层可以同时使用 Repository 和 Service 类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

如果表示层只应该使用服务,那么服务类必须公开存储库已经实现的相同方法,以使它们可用于表示层.

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.

应用服务是facades.糟糕的外观是一种增加的复杂性而不是它解决的问题.像这样:

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 中,表示层可以同时使用 Repository 和 Service 类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-17 01:43:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/901387.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Repository   DDD   类吗   Service

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!