Description
As far as I can see, there's no official out of the box support for feature folders in asp.net core mvc, but the framework is extensible enough that many people came up with a simple pattern on how to make it work (see this, this or this)
I'm assuming there might be enough interest in adding support for them in r4mvc, alongside support for Pages, a different new feature also added to asp.net core.
Based on the above it's probably safe to assume that most people will put all their feature folders in a single parent folder (usually /Features/
+ /Areas/{area}/Features/
), which we can also make configurable. Within that folder you'd have a set of static files, controllers view model classes and razor templates, either in the root or grouped by feature folder.
This will make it easy picking up the features content, and filtering it from other content present in the app. Any content present in the Features folder will be available for content generation and static content access.
Considering the fact that making feature folders work requires extra configuration, it will be a disabled feature by default, but can be easily enabled using r4mvc.json. There are a couple settings that we can add, and we can group them in a separate object:
{
"featureFolders": { // if this object is present, feature folder generation is enabled
"featuresPath": "Features", // default value, but technically there in case anyone wants to override it
"staticFileAccess": true
}
}
We have to make sure that feature folders can coexist with existing controllers structure. That's one of the reasons why the Features folder is a good idea.
One side-effect of feature folders is the fact that the same controller name can exist in multiple features, which will cause a clash. That's something that will inevitably happen, and is not something we can easily guard against. Neither will the framework (as far as I understand, the first matching controller only will end up processing requests). A special case would be if all the controllers are manually forced to be in the same namespace, we should also make sure that this works :)
Original post, pre update
To support this, we need to consider several things.
- How will the feature controllers be accessed from the r4mvc generated classes?
- What kind of pattern will we support?
It's probably safe to assume that most people will put all their feature folders in a single parent folder (usually
/Features/
+/Areas/{area}/Features/
), which we can also make configurable. Within that folder you'd have a set of static files, controllers view model classes and razor templates, either in the root or grouped by feature folder.Luckily for us, thanks to the way t4mvc/r4mvc works, we don't have to worry about how they are wired up (whether the user has wired up using something like this, this or this
I suggest the following:
- Add generated entries for all feature controllers, and add an extra route parameter to them named by the feature name (route parameter defaults to
feature
) The extra route parameter can be disabled, or renamed using settings. This would allow us to support all of the above ways of using it, while also supporting the use case when the feature folders are ONLY used for organisational/structural purposes- All feature folder content (controllers, views) can be accessed using the
MVC.Features.[...]
prefix. So a controller in/Features/Toolbar/HeaderController.cs
will be accessed usingMVC.Features.Toolbar.Header.Index()
- Feature folder static content can be accessed using
MVC.FeatureLinks.[...]
prefix and will act in the same way asMVC.Links.[...]
for static content in wwwrootThis is related to #91 and #92, which don't seem to work yet, and I'd rather have a more structured approach to this.