Search code examples
asp.net-mvc-23-tier

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 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!


Solution

  • 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.