views:

122

answers:

2

Hoping the SO community can help to resolve a debate in the office. At the moment our conclusion is 'it depends' !

In MVC, how do you organise your namespaces?

Option A

Do you go down the MS ASP.NET MVC route of having a Models, Controllers and Views namespace?

Option B

Or do you separate each MVC triad into it's logical 'function', for example:

Feature A

  • FeatureAModel
  • FeatureAController
  • Types
    • IFeatureAView (interface - so that controller DOESN'T ref a concrete View)
  • View
    • FeatureAView (concrete)

We can see the point of both. I like Option B as it structures my projects in studio better - at a glance I can see where everything is as it's grouped by Feature. But Option A gives us an easier scaling option if we want to move all our Models out into a service layer in the future, for example.

All thoughts welcome!

+1  A: 

I prefer a combination of both in a hierarchy. Your option A is my top level and inside that feature wise.

Bhushan
A: 

I personally tend to favour the idea of keeping all my controllers within the same namespace, solely due to the fact the by default the routing is not namespace aware.

This means that if I try to name my controllers the same name, I get a compiler time error rather than a weird runtime error about routing.

Anyway there have been quite a few blog posts that you can search on google for more information about this.

So I would say

Option A

Barry