我可以从表示层访问存储库吗? [英] Can I access a repository from presentation layer?

查看:26
本文介绍了我可以从表示层访问存储库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 DDD 开始.我对 DDD 应用程序中涉及的几个层之间的交互有点困惑.

我可以从我的表示层调用我的存储库吗?如果不是,我是否必须在我的服务层中复制存储库提供的 CRUD 功能(这当然会反过来将存储库用于这些功能)?这样做的最佳方法是什么?

解决方案

表示层到底是什么意思?如果您指的是控制器/演示者,那完全没问题.我使用的经验法则是,如果控制器操作是 4 行或更多代码,我应该考虑重构为应用程序服务类,但仍然 - 两者都在应用程序级别,您当然可以在那里使用存储库.

您提出问题的方式 - 我当然可能会误解这一点 - 听起来很可疑,就像您正在考虑从您的视图或代码隐藏中引用存储库一样.在这种情况下,我会说不!不!不!

I am starting with DDD. I am a bit confused with the interaction between the several layers involved in a DDD application.

Can I call my repositories from my presentation layer? If not do I have to replicate the CRUD functionality provided by the repositories in my service layer (which ofcourse will in turn use the repository for these functions)? What would be the best way to do this?

解决方案

What exactly do you mean by presentation layer? If you mean the Controller/Presenter, then it's perfectly fine. The rule of thumb that I've used is if the controller action is 4 lines of code or more I should look at refactoring to an application service class but still - both are at the application level and you can certainly use repositories there.

The way you phrased your question - and I could certainly be misinterpreting this - sounded suspiciously like you were thinking of referencing the repository from your view or codebehind. In that case I would say no! no! no!

这篇关于我可以从表示层访问存储库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆