What are some MVC best practices
Best Practices for MVC Architecture [closed]
My question is more about the architecture of an MVC application. For example, it is recommended to use DI with the repository pattern to decouple data access from the controller. However, very little is said about how to do this specifically for MVC. For example, where would we put the repository classes? They do not seem to be model-specific, as the model should also be relatively decoupled from the actual data access technologies.
A second question concerns the structuring of the levels or layers. Most of the sample applications (nerd dinner, music store, etc) all seem to use a one-step, 2-level approach (without counting tests) where controllers usually call L2S or EF code directly.
If I want to build a multi-tier / layer application, what are the best practices for MVC?
DI is run in ASP MVC using a controller factory. This factory is used to resolve your controller dependencies.
MvcContrib has some Controller Facotry implementations that you can use right out of the box. I'm using their Castle Windsor implementation and it works fine. I would also suggest checking out their TestHelper class. It has some very cool functions for mocking Controller HTTPContext, Sessions, etc. MVCContrib
Personally, I want to give my models a repository instance to work with. The model exposes an API to the repository (CRUD). The controller's dependency on a specific model is injected when it is created (constructor). This is injected via the controller factory. This is my entry point into the object diagram managed by my IoC container.
For example, where would we put the repository classes?
They belong in the model; They are the in-application model.
How do I structure the levels? If I want to build a multi-tier / layer application, what are the best practices for MVC?
Layers represent physical code separations. Layers represent logical separations. The layers (as they currently are) work fine for MVC. Depending on the scope of the business logic, this can either be placed in your controller or in a separate assembly and used by the controller during the request cycle.
- Why can't we let shrinking rays grow?
- What is the worst hotel in Guyana
- What does fee mean
- Greetings are always returned in the military
- What is your most memorable bird of life
- Difference between in smo and smm
- No audio after Windows 7 Clean installation
- Is there an active eco-terrorist group?
- Why are airports so tastefully designed
- What is georgism
- How accountable is the Canadian government
- Will a smart TV replace a desktop
- Produces laughter dopamine
- Is It expensive to live in Maine
- Why don't cats live longer
- What is a Parama Anu
- Which country is your home
- How do vacuum water bottles work
- Will the Brexit take place on Halloween?
- How did you cure your ideopathic gastritis
- Who inspired you to paint?
- How will Pakistan buy drones from China
- Are storage facilities good commercial properties
- What is the significance of the debate about atheism