views:

1008

answers:

4

I've been reading a few things about ASP.NET MVC, SOLID and so on, and I am trying to figure out a simple "recipe" for small-to-medium ASP.NET MVC apps that would put these concepts together; the issue that I am most concerned with is ending up with controllers that are too complex and being like code-behind files in webforms, with all type of business logic into them.

I am considering the following architecture, for a small data-driven app:

  • Controllers: only handle requests, call an appropriate service and return the action result to the View;
  • Models: POCO, handle all the business logic, authorization etc. Depends on repositories, totally ignorant of persistence infrastructure.
  • Repositories: implement IRepository<T>, use dependency injection and is where my db code will reside; only receives and returns POCO.

I am considering having services between the controllers and the models, but if they will just pass forward method calls I am not sure how useful it would be.

Finally there should have unit tests covering the model code, and unit+integration tests covering the repository code (following the "red-green" practice, if possible)

Thoughts?

+6  A: 

Ian Cooper had a good post on exactly this recently:

The Fat Controller

Zhaph - Ben Duguid
+1  A: 

Rob Conery has the best answer IMO.

Check out his MVC Storefront Application, which comes with complete source code and video tutorials.

Pure.Krome
The thing with Rob Conery's videos is that for those who haven't followed from the beginning, now's it's like 30 hours of video to watch..not easy. Another problem with the video format is searchability. I wish he had done this through blog posts instead.
rodbv
+2  A: 

Simple recipe: (view)Presentation Layer using ASP.NET, (controller)Code Behinds or AJAX Services Layer, (model)Application Services layer, Business Model layer, and Persistance/Data Access layer.

Of course you can slice and dice numerous ways to deal with complexities in order to build a clearly readable and understandable application.

For a recent discourse on the subject, which I have found to be very good, check out this newly published book: Microsoft .NET: Architecting Applications for the Enterprise.

daduffer