Created
May 15, 2012 16:51
-
-
Save darrelmiller/2703205 to your computer and use it in GitHub Desktop.
Hierarchical MVC routing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var router = new ApiRouter("api").DispatchTo<RootController>() | |
.Add(new ApiRouter("Contacts").DispatchTo<ContactsController>()) | |
.Add(new ApiRouter("Contact").WithHandler(new LoggingHandler()) | |
.Add(new ApiRouter("{contactid}") | |
.WithConstraint("contactid", @"\d+") | |
.DispatchTo<ContactController>() | |
.Add(new ApiRouter("Address") | |
.Add(new ApiRouter("{addressid}") | |
.WithConstraint("addressid", @"\d+") | |
.DispatchTo<AddressController>() | |
) | |
) | |
) | |
); | |
// or | |
var router = new ApiRouter("api").DispatchTo<RootController>() | |
.Add(new ApiRouter("Contacts").DispatchTo<ContactsController>()) | |
.Add(new ApiRouter("Contact({contactid})") | |
.WithConstraint("contactid", @"\d+") | |
.WithHandler(new LoggingHandler()) | |
.DispatchTo<ContactController>() | |
.Add(new ApiRouter("Address({addressid})") | |
.WithConstraint("addressid", @"\d+") | |
.DispatchTo<AddressController>() | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment