I've developed my first few pages in MVC and I am re-considering how I have organized my code. We will have multiple pages (Views) that I want to group in one controller. So we may have a Finance controller, a HumanResources controller, an Admin controller,
etc. Finance would then have several Views in the Views/Finance folder and so on. I see most of the code being placed in models and stored procedures (on the database). The controllers would be lightweight basically just taking a request, gathering the
data from the model, and then returning it to the View. Is it normal that most of the code lies in the models and stored procedures, or how do others organize their MVC projects?
It all depends on the project type and scope. Usually i dont want to mix a lot of business logic in my model classes. I would keep them as simple POCO ( plain old class object)s to represent my domain model. Basically, I would seperate my domain entities
and data access into a seperate project. So i will have my project structure like this
UI Project : My basic MVC stuff : My Controllers , Views , ViewModels, Scripts , Images etc...
Business Entities : My POCO's for domain models. I would use these to generate my database if i am goind to do codefirst approach ( Created database from your entities ) .
DataAccess : This project will have the Data Access code. It can be typical ADO.NET with stored proc or Entity framework or any other ORMs. I will add a reference to my Businesss Entities project here so that i can use them here.
In my UI Prokect, I will add references to my Entities and DataAccess project.
If my project has view model , I would add a mapping/Service layer as well to map my domain model objects to the ViewModels.
And YES. I like to keep my controllers clean. I usually call the methods in my service layer to get he data / objects which calls my service data access layer.
DallasSteve
Member
221 Points
331 Posts
Where does most of your code reside in MVC?
May 25, 2012 09:19 PM|LINK
I've developed my first few pages in MVC and I am re-considering how I have organized my code. We will have multiple pages (Views) that I want to group in one controller. So we may have a Finance controller, a HumanResources controller, an Admin controller, etc. Finance would then have several Views in the Views/Finance folder and so on. I see most of the code being placed in models and stored procedures (on the database). The controllers would be lightweight basically just taking a request, gathering the data from the model, and then returning it to the View. Is it normal that most of the code lies in the models and stored procedures, or how do others organize their MVC projects?
www.SteveGaines.us
kshyju
Member
134 Points
39 Posts
Re: Where does most of your code reside in MVC?
May 25, 2012 11:26 PM|LINK
It all depends on the project type and scope. Usually i dont want to mix a lot of business logic in my model classes. I would keep them as simple POCO ( plain old class object)s to represent my domain model. Basically, I would seperate my domain entities and data access into a seperate project. So i will have my project structure like this
UI Project : My basic MVC stuff : My Controllers , Views , ViewModels, Scripts , Images etc...
Business Entities : My POCO's for domain models. I would use these to generate my database if i am goind to do codefirst approach ( Created database from your entities ) .
DataAccess : This project will have the Data Access code. It can be typical ADO.NET with stored proc or Entity framework or any other ORMs. I will add a reference to my Businesss Entities project here so that i can use them here.
In my UI Prokect, I will add references to my Entities and DataAccess project.
If my project has view model , I would add a mapping/Service layer as well to map my domain model objects to the ViewModels.
And YES. I like to keep my controllers clean. I usually call the methods in my service layer to get he data / objects which calls my service data access layer.
My flarack profile
CPrakash82
All-Star
18154 Points
2831 Posts
Re: Where does most of your code reside in MVC?
May 25, 2012 11:31 PM|LINK
Please see the below project designed in MVC and they have good architecture in place.
http://oxite.codeplex.com/wikipage?title=architecture&ProjectName=oxite
http://code.google.com/p/sharp-architecture/
http://silk.codeplex.com/
ASP.NET Storefront application
Excellent blog on controller responsibility.
http://codebetter.com/iancooper/2008/12/03/the-fat-controller/
Regards,