ASP.NET MVC 2 在哪里放置逻辑

发布于 2024-10-10 11:42:59 字数 283 浏览 0 评论 0原文

我有一个 ASP.NET MVC 2 应用程序,其中包含一些复杂的业务规则,我正在尝试决定将特定逻辑放在哪里。

创建记录时会发生逻辑,根据该记录的某些字段需要创建其他记录。

我目前正在使用带有 ORM 的存储库模式,放置此逻辑的最简单位置是在我的存储库类中,但我觉得这是一个非常薄弱的​​位置,无法容纳重要规则,我会将其直接放在我的部分模型类中有我的验证和元数据,但我必须调用我的控制器或存储库中的方法,这可能会将太多有关实现的知识扩展到这些层。

您对我来说的最佳实践建议是什么?

谢谢!

I have an ASP.NET MVC 2 application with some complex business rules and I'm trying to decide where to put specific logic.

The logic happens when creating records, based on certain fields of that record other records need to be created.

I'm currently using the repository pattern with an ORM and the easiest place to put this logic would be in my repository class but I feel like this is a pretty feeble location to have important rules, I would put it directly in my partial model classes that have my validation and metadata but I then have to call methods within my controller or repository and that may be extending too much knowledge about implementation to those layers.

What are your best practice tips for me?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神妖 2024-10-17 11:42:59

您可以在控制器和存储库之间有一个服务层。该存储库对您的模型执行简单的 CRUD 操作。服务方法可以利用多个简单的存储库调用来组成业务操作。该业务操作将暴露给控制器。

You could have a service layer between the controller and the repositories. The repository performs simple CRUD operations with your model. A service method could make use of multiple simple repository calls to compose a business operation. This business operation will be exposed to the controller.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文