Should controllers in an ASP.NET MVC web app call repositories, services, or both?

后端 未结 7 1630
生来不讨喜
生来不讨喜 2021-01-30 09:22

The controllers in my ASP.NET MVC web app are starting to get a bit bloated with business logic. The examples on the web all show simple controller actions that simply pull dat

7条回答
  •  耶瑟儿~
    2021-01-30 10:13

    Your business logic should be encapsulated in business objects - if you have an Order object (and you do, don't you?), and a business rule states that an email should be sent when the Order is fulfilled, then your Fulfill method (or, if more appropriate, the setter for IsFulfilled) should trigger that action. I would probably have configuration information that pointed the business object at an appropriate email service for the application, or more generally to a "notifier" service so that other notification types could be added when/if necessary.

提交回复
热议问题