The support of "areas," or groups of controllers and views organized into modules, in a medium or large sized application is absolutely vital. It seems quite bewildering to me that Microsoft intends on releasing ASP.NET MVC 1.0 without built in support for areas.
Fortunately, what ASP.NET MVC framework lacks in capability is made up with extensibility. It really is quite extensible, allowing you to replace parts of it as needed. For example, for S#arp Architecture, I took guidance from Phil Haack and Steve Sanderson but modified the merged result to support areas directly under the Views folder. (I didn't like that there was a separate "Areas" folder to hold your areas; granted, their areas assumed that they'd also be holding the controller for each area as well.) The result supports subfolders under the Views folder which reflects the namespace of your model. For example, if you create a domain object namespaced as Store.Core/Warehouse.Inventory.Product with a corresponding controller Store.Web.Controllers/Warehouse.Inventory.ProductsController, your Views folder would reflect Store.Web/Views/Warehouse/Inventory/Products. You could then browse to http://YourServer/Warehouse/Inventory/Products to see a listing of products.
This was only possible due to the fact that much of ASP.NET MVC is "replaceable" with your own parts. For example, as Haack suggested, you can write your own view engine to handle the matching of requests to views, per the needs of the application. A working example from S#arp Architecture best illustrates. (Even if you're not interested in using S#arp Architecture, I would encourage you to check out how areas were implemented in it for use in your own application.) The relevant code includes:
With the above, you'd be able to browse to http://YourServer/Organization/Employees/Index and the views would be hierarchically organized under the Views folder. Incidentally, S#arp Architecture includes a CRUD scaffolding generator which takes into account nested namespaces automatically.
Although it's too bad that ASP.NET MVC won't support areas natively, it's pleasent to realize just how customizable the entire MVC framework really is, to allow us to fill in any missing gaps ourselves.
01-22-2009 4:42 PM