views:

72

answers:

2

Visual Studio tooling will create "Models", "Views" and "Controllers" folders in any new ASP.Net MVC 2 Area.

Areas Folder in Visual Studio

What else should go into this folder? Would you (for example) place custom ModelBinders in Areas/MyReallyGreatArea/Binders if they are only referenced in MyReallyGreatArea?

What is the best practice?

A: 

Personally I like to keep the areas folder as lean as possible, however it depends on your project size. If you have a large 'web' project then you probably want to keep your models/binders and other plain objects in a seperate library for your business logic, alternatively if you only have a couple of areas and few other classes required then there I like the idea of keeping your area specific binders under the area folder.

I don't like shared plain classes floating around the 'web' project and beleive these should be in a seperate library, however your code may not be large enough to justify this.

Toby
+1  A: 

Yes, when I a custom ModelBinder in MyReallyGreatArea only I put it - as you suggested - into a folder within that area, e.g. Areas/MyReallyGreatArea/Binders. When a ModelBinder is later used by a different area I then move it up into a folder named Areas/Shared/Binders or similar. That way I keep classes located close to where they are used. Why bother with the customer ModelBinder if MyOtherEvenGreaterArea doesn't use it?

The same applies for everything else. If it is used by MyReallyGreatArea only it will be located in there. If it is shared with a different area I put it into Area/Shared (and possibly properly named subfolders in there).

While this is likely to be only a minor issue if you work alone on this project or when then the project is still small, a well thought-through structures pays off as the project grows or as a larger team works on it. In some cases different areas are even worked on by different teams.

John