Overview
The Bind attribute specifies the structure of URLs that should be serviced by the marked controller.
Usage
This attribute is specified for class-level usage. Multiple attributes can be present on a single class. Multiple bind attributes with the same URL structure on the same class will produce a run-time exception.
Target
The target parameter specifies a matching pattern for incoming urls. The url structure supported is of the form
ACTION/element1/element2/../elementN
where
ACTION is one of
- GET
- POST
- PUT (future functionality)
ACTION can be omitted. If missing, all HTTP methods will be evaluated.
elementN is one of
- a string literal (/hello/world)
- a parameter name, enclosed in {braces} (/hello/{world}). The value enclosed in the braces should match a property or field of the controller class. Not having a property or field with a matching name will is valid, and will simply omit the parameter, treating it as a local wild-card.
- a local wild-card *. A local wild-card will match any single elementN.
- a global wild-card ?. A global wild-card will match 0 or more consecutive elements.
Wild-card rules
The * and ? characters denote wild-card matching behavior, and follow special rules.
The * character will match any single component of an incoming URL. Therefore, given a bind pattern of /hello/*/how/are/you, the url /hello/world/how/are/you will be matched, however, /hello/new/world/how/are/you will not. Additionally, /hello/how/are/you will not be matched either, as the wild card will match the /how component, leaving are/you for the remainder of the pattern, which still expects /how/are/you.
The ? character will match any sequence of 0 or more consecutive elements. This means that /hello/?/you should match request /hello/how/are/you skipping /how/are, and resuming the match on /you. However, the same bind point will not match request /hello/world, as there is no trailing you. note that this disallows consecutive wild cards such as /hello/?/? and /hello/?/*, but does allow /hello/?/how/*, and so on.
Trailing parameter components
If a bind pattern has 1 or more trailing parameter components (such as /hello/{world}), and an incoming url does not provide component values for them, a match will still occur, and the parameters will be set to null. E.g. the url /hello will match the bind pattern /hello/{world}, and set the controller's world property to null.
Priority
The priority parameter is a last-resort mechanism for specifying controller execution order. It is generally used to enforce order of global controllers, and is not recommended for normal use. All controllers are defaulted to a value of -1. Higher values imply earlier execution/
ControllerBindType
The execution model is patterned after the Pointcut concept in AOP. Each execution has a payload, typically the rendering process, and controller executions are meant to be pointcuts Before, After, or Insteadof (Payload) the payload. The ControllerBindType provides values to describe at what stage the controller should be executed. Note that the rules described by the Provides, Requires and DependsOn attributes supersede both the Priority and Bind Type order rules.
Example
Bind to request for a specific ad, of the form /content/ad/{adId} where adId is the id of the ad to retrieve. The value of {adId} will be placed into the adId field.
[Bind("/content/ad/{adId}")]
public class Ad : AbstractController
{
[Request]
protected string contentType;
[Request]
protected Posting ad;
protected string adId;
public override void DoProcessRequest(IExecutionContext context)
{
ad = PostingHelper.Instance.LoadPosting(null, adId);
contentType = ContentType.Resume.Equals(ContentTypeHelper.Instance.GetLastDefault()) ? "resume" : "ad";
context.RenderWith("/Templates/Ad/view.bistro");
}
}
Bind to all requests, and make sure to run before everyone else does
[Bind("?", Priority = 1)]
public class DefaultController: AbstractController
{
...
}