tags:

views:

199

answers:

5

hi, maybe i am wrong but i seriously i don't like the current structure of MVC application, and i think on big projects it will cause trouble to maintain.

so is there a way to group related Controllers,Views, Models together, like if i have gallery Module i want all it's Controllers, Views, Models to be grouped under Gallery Folder.

thanks in advanced.

+3  A: 

Areas sound like what you are looking for. This will let you group controllers/views/etc. Unless I misunderstood the question?

Chad Ruppert
exactly man, that is what i want.
+1  A: 

From the sound of it you're moving against the basic principals of MVC, that being the separation of Model, View and Controller rather than your desire to split at 90 degrees to that by using modules.

I'm not entirely sure what benefit you would get from splitting it in to modules any way since I would expect you to have one GalleryController. Where you are likely to have the most 'entities' needing grouping is with the views, possibly one or more for each GalleryController action, but they are in their own folder which gives the sort of functionality you are looking for anyway.

Finally there are the models. Obviously I don't know your project so I don't know how it is laid out, but the Models do not usually exist for the use of one Controller (or module in your case). For example - I have Models for Users, Companies, Vehicles, etc, etc. These models are a shared representation of my data structure and have nothing to do with modules as a user may see it looking at a web page. I can't split them in to modules because the whole point is that they are shared by the entire application.

So...in reality it is the Views which can get a bit messy, but they are already split in to folders based on their Controller. Having said that you can move them around a bit if that suits your needs better. For the rest of it there is no need, either because you shouldn't if you want to use 'proper' MVC (i.e. modular Models) or there's no need (i.e. only one Controller). And if your controller gets too big just create a separate module for any functionality in that you want to split out. I reckon that's as modular as you should ever need to get.

Jason
thanks for your valuable input man.
+2  A: 

Phil Haack discussed this here, it's the same issue I've faced and have yet to overcome correctly.

Kezzer
thanks for the link man
+1  A: 

I found a relatively simple solution that uses IIS configuration to simulate areas. No extensions to the existing MVC framework are needed.

Create a new MVC project under your solution for each area you want in your site (ex. Root, Blog, Forum, App1, App2). If you need any common supporting code or a common model, put it in a seperate dll project that the MVC projects depend on.

In IIS, configure the site root to point at the root project directory. Create web applications under the site root that point to each of the sub-area project directories.

When configuring the route maps for each sub area, don't include the name of the application in the route. IIS seems to take care of this for you. (ex. "ShowPost/{postname}", not "/Blog/ShowPost/{postname}")

The benefit is that you can change the name of the web applications independent of the routing system, and each application believes it is running with the whole server to itself.

Ryan Michela
great tip, but unfortunately i am on a shared hosting :(
A: 

Do we have similar feature in Rails?

If you know of one, please write to my question here: http://stackoverflow.com/questions/2631501/grouping-controllers-and-views-in-rails-mvc

Thanks

jaycode