开发者

ASP.NET MVC 2 Where to put logic

I have an ASP.NET MVC 2 application with some complex business rules and I'm trying to decide where to pu开发者_运维技巧t 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜