Separation of concerns – Application Layers

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

Advertisements

About eidand

Senior Dot Net developer specialised in C# / Sql Server / Mvc / Wcf
This entry was posted in Code and tagged , , , , . Bookmark the permalink.

3 Responses to Separation of concerns – Application Layers

  1. smithjeric says:

    You definitely have my attention. This sounds very similar to the way I architect my solutions. I’m currently on my mobile but will download your source this eve and check it out.

    Thanks for the link.

  2. eidand says:

    great, thank you. I would love to have feedback. We all seem to build things in different ways !

  3. smithjeric says:

    I’m working on an architecture now to enable switching out persistence without affecting any other layer. I may post about it on LinkedIn for some insight.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s