Skip to content

Conventional routes and route policies

chadmyers edited this page Apr 23, 2011 · 5 revisions

Conventional routes and route policies

Default 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.

Example

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

Default Route Policy Options

In your FubuRegistry, using the Routes statement, you can chain a number together of different route/url policy options and modifications.

Manipulating the Route URL

Manipulating the namespace portion of the route

  • IgnoreNamespaceText Removes all or a portion of the namespace section of the route. For example, if you ignore fubumvc.helloworld then the example route mentioned above would be shortened to controllers/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 class T 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

Manipulating the class portion of the route

  • 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 by T 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

Manipulating the method portion of the route

  • IgnoreMethodsNamed
  • IgnoreMethodSuffix

Manipulating the input parameter portion of the route

  • IgnoreSpecificInputForInputTypeAndMethod
  • IgnoreInputsForInputTypeAndMethod

One-off, special case manipulations

  • AppendClassesWith(actioncall filter, patten)
  • AppendAllClassesWith(pattern)
  • ModifyRouteDefinitions
  • ForInputTypesOf<T>...RouteInputFor
  • ForInputTypesAndMethods(filter)

Constraining route via HTTP properties

  • ConstrainToHttpMethod

Defining custom route URL policies

  • UrlPolicy(type)
  • UrlPolicy<T>

Establishing which controller handles the / route

  • HomeIs<Controller>(action)
  • HomeIs<InputType>()