Dharmik Bhandari
Dharmik Bhandari

Reputation: 1702

Best practices to organize code in mvc3 application

I want to make one mvc3 application which is student management. I've seen some open source projects. They have used solution structure like core,data serve rice. is there any reason to use structure like this?

Upvotes: 2

Views: 664

Answers (3)

JasonD
JasonD

Reputation: 1016

As stated in the previous answers, you should separate your logical tiers into a minimum of BusinessLogic (Entities,validation,etc..), Data(your favorite ORM), and presentation (MVC).

However, if you are just starting out it may be a little daunting to incorporate all of the more advanced concepts of a SOLID architecture.

Separating logical tiers doesn't always have to mean separate projects. The standard MVC3 template demonstrates this with the "Models" folder. Any entity added to this will be under the namespace Myproject.Models. Later you could re-factor the code in the Models folder into a separate dll,add a reference, and as long as the namespace was still Myproject.Models the MVC app will continue to work.

The same thing could be done for your Data Access layer!

If you're just starting out I would recommend developing your app in the MVC project and separating your DAL and Business Layers with a Folder (Namespace). Once your application is working you can re-factor as needed.

Upvotes: 2

jgauffin
jgauffin

Reputation: 101192

Use layered architecture where you isolate each layer by using the Separated Interface pattern. For the database, use Repository pattern (easiest way to archive that is to use a ORM like nhibernate).

Use an inversion of control container to reduce coupling (with the help of interfaces) and make it easier to handle dependencies between classes.

Upvotes: 3

user353955
user353955

Reputation:

Usually it is a good a good idea to keep things separated.

By that I mean not mixing up business logic with database management code and having non-UI code in the view files.

This makes it a lot easier for others to understand the code you have written. I also helps you, when you get back to some project after some time to make improvements or correct errors.

I hope this answered your question, if not shot again.

Edit: I found this link explaining how it is done in the MVC framework.

Upvotes: 3

Related Questions