Reputation: 41
I'm starting my first serious ASP.NET MVC application and I need someone to explain me how to properly layer it. (all of apps I have created so far where just test apps and I didnt care about properly layering it)
I've spent a while searching the web for example of properly layered MVC application but all of theme where either incomplete or where just ton of text with no real example.
Let's say I have e-commerce website (any other example will be fine), could someone write me an example of how would you structure this app (for example when user buys the product)
What would your interfaces and classes look like where would you place them, where would you place classes for fetching data from database and so on. I dont need the implementation of this classes just their name position and function or properties they hold
For example
IProduct -> interface in 2nd project (Project.Whatever -> someFolder)
Properties: Name, Price ...
IProductRepsitory -> it's position in project
Functions: BuyProduct(Product product)
Now when you have defined all details that you think would be needed to understand your example please write down details of program flow from the controller till the view is generated, which function do you call from controller which function calls function you have called from controller and so on till you finally get to part where you go back to controller and generate view.
I know that this will take bit longer post to explain but you don't need to go in too much details but just enough so I can understand how to properly layer mvc application
Thanks in advance
Upvotes: 4
Views: 594
Reputation: 60468
At first i have to say that i don't know how experienced you are with programming in general, thats makes it hard to answer all your questions.
I would say that you should have a look on the .net framework, no joke, in terms off understanding seperation of concern. Thats one of the most important things and answer your question "What would your interfaces and classes look like where would you place them".
One sample.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace YourCompanyName
{
// here goes only stuff that could use in
// EVERY kind of .NET Application...
// The classes that are placed here dont
// know windows, the internet, phones or ...
}
namespace YourCompany.Web
{
// here goes only stuff that could use in
// any Asp.NET Application.. Mvc and Webforms
// like request helpers... Only Asp.NET related
// stuff
}
namespace YourCompany.Web.Mvc
{
// here goes only stuff that could use in
// Asp.NET Mvc Application.. like HtmlHelpers or
// EditorTemplates
}
namespace YourCompany.Web.Forms
{
// here goes only stuff that could use in
// Asp.NET WebForms Application.. like WebControls
}
// and so on
and so on, if you do something with Windows Forms ?, YourCompany.Windows.Forms
and you
extend the System.Windows.Forms
Assembly.. thats the right way to think.
In point Asp.NET there are the guys
and many more that i encourage you to read their blogs and see their webcasts.
In point of Asp.NET MVC you MUST see these two videos by Scott Hanselman. You can learn so much in a short time, its fun and motivating.
ASP.NET MVC 2: Basics, Introduction by Scott Hanselman
ASP.NET MVC 2: Ninja Black Belt Tips by Scott Hanselman
And download THE demo application to learn asp.net mvc, see how you could structure your application. =>
NerdDinner see it live on NerdDinner.com
Hope that helps!
Upvotes: 3