This isn’t meant to be a guide. It is meant to show how I like to structure my applications and get some feedback, maybe there is a better or cleaner approach or maybe I don’t go far enough.
The project is zipped up and you’re welcome to download it and look at it for reference.
So, without any more delay, let’s jump right into it. A little context before the code though.
Lately, I have been doing a lot of mobile work and almost every time, I need to add a mobile interface, in addition to a standard web interface. The way I structure this project reflects that requirement.
So I start by creating an MVC project. This is the UI for this example.
Then a DTO – DTO stands for Data Transfer Object and I am using it to get data from the database and serve it somewhere, more than likely over a webservice, which is why it needs to be small and serializable. Anything that comes from a datasource goes out as a DTO, I never ever return a class created by an ORM. This is in case I want to change the ORM and use ADO. NET or I just need to change things. If I return DTOs then I am not coding myself into a corner, should I ever want to change things.
Then we have the Business Layer, this is where all the business rules are applied. To make things simple, I pass a DTO in the constructor and run the rules in the same place.
Finally in the UI project is where things are glued together. The UI project is the only one that references all the other projects. It will get the data, populate the business objects and finally get that data into a model, ready to be passed to the view. I kept it simple as well, just to show how things work.
The interesting bit happens in Home controller, Index action. Yes this means the controllers are a bit fat and this is perhaps where I could look further.
I would like some feedback though and see what other technical people think.
You can download the code for this post here