-
Notifications
You must be signed in to change notification settings - Fork 151
Conventional routes and route policies
Route policies are applied after Action discovery. The list of discovered actions (represented by the ActionCall object are fed into the route policies. Conventional and explicit route policies are applied at this point to determine the actual/final route for each action.
?? WHAT IS AN ACTION ??
?? WHAT IS AN ACTIONCALL ??
?? WHAT IS A ROUTE ??
Without configuring anything in your FubuRegistry, Fubu MVC will follow the default policies, specified below, for discovering routes. Route policies either explicity state what the route will be for an action, or will determine it by examining the ActionCall object.
- If the action is marked with the
UrlPattern
attribute, this pattern is used immediately and all further policy evaluation ceases. - If the action is marked with the
FubuPartial
attribute (or otherwise marked as "IsPartialOnly" = true), then the action becomes non-routable and receives no route. - (If any custom policies were specified, they would be evaluated at this point)
- The text "Controller" is stripped from the end of name of the class which contains the action.
- Any properties on the input model of the action that are decorated with the
RouteInput
attribute are considered as route inputs (see below for details on route inputs). - Any properties on the input model of the action that are decorated with the
QueryString
attribute are considered as query string inputs to the route (see below on details for query string inputs) - The route will be: fully/qualified/namespace/classname/actionname
PROTIP. If you find yourself wondering how a particular action ended up with the route it has, check out the Fubu MVC Diagnostics for that Behavior Chain and examine the log. It should describe the process of evaluating each URL Policy until there was a match.
The end result of the default policies for the given class and action method:
namespace FubuMVC.HelloWorld.Controllers.Home
{
public class HomeController
{
public HomeViewModel Home(HomeInputModel model)
{
return new HomeViewModel();
}
}
}
Would be the route:
fubumvc/helloworld/controllers/home/home
In your FubuRegistry, using the Routes
statement, you can chain a number together of different route/url policy options and modifications.
-
IgnoreNamespaceText
Removes all or a portion of the namespace section of the route. For example, if you ignorefubumvc.helloworld
then the example route mentioned above would be shortened tocontrollers/home/home
. Corresponding unit test: RouteDefinitionResolverTester.build_route_with_a_namespace_ignore() -
IgnoreNamespaceForUrlFrom<T>
Removes all or a portion of the namespace section of the route using the entire namespace from a given classT
as the pattern to remove. You can use this to reference a controller or a simple empty marker class in the parent namespace as your controllers to remove that portion of the namespace from your routes. IgnoreControllerFolderName
IgnoreControllerNamespaceEntirely
-
IgnoreClassSuffix
Ignores a portion of the class name when constructing the route URL. For example, the "Controller" portion of "HomeController". Corresponding unit test: RouteDefinitionResolverTester.build_route_when_ignoring_suffix_of_controller_name() -
IgnoreClassNameForType<T>
Ignores the entire name of the class specified byT
when constructing the route URL. This is useful if you don't want the class containing the action method to appear in the route URL. IgnoreControllerNamesEntirely
IgnoreMethodsNamed
IgnoreMethodSuffix
IgnoreSpecificInputForInputTypeAndMethod
IgnoreInputsForInputTypeAndMethod
AppendClassesWith(actioncall filter, patten)
AppendAllClassesWith(pattern)
ModifyRouteDefinitions
ForInputTypesOf<T>...RouteInputFor
ForInputTypesAndMethods(filter)
ConstrainToHttpMethod
UrlPolicy(type)
UrlPolicy<T>
HomeIs<Controller>(action)
HomeIs<InputType>()