Created
August 20, 2012 19:03
-
-
Save emiaj/3406752 to your computer and use it in GitHub Desktop.
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
| [AttributeUsage(AttributeTargets.Method)] | |
| public class UrlAliasAttribute : Attribute | |
| { | |
| private readonly string _url; | |
| public UrlAliasAttribute(string url) | |
| { | |
| _url = url; | |
| } | |
| public string Url | |
| { | |
| get { return _url; } | |
| } | |
| } | |
| public class UrlAliasConvention : IConfigurationAction | |
| { | |
| public void Configure(BehaviorGraph graph) | |
| { | |
| graph.Actions() | |
| .Where(x => x.Method.HasAttribute<UrlAliasAttribute>()) | |
| .Where(x => x.HasInput).ToList() | |
| .Each(x => | |
| { | |
| var url = x.Method.GetAttribute<UrlAliasAttribute>().Url; | |
| var chain = new BehaviorChain(); | |
| var handlerType = typeof (UrlAliasHandler<>).MakeGenericType(x.InputType()); | |
| var handlerMethod = handlerType.GetMethod("Execute"); | |
| var call = new ActionCall(handlerType, handlerMethod); | |
| call.AddAfter(new ContinuationNode()); | |
| chain.AddToEnd(call); | |
| chain.Route = call.BuildRouteForPattern(url); | |
| graph.AddChain(chain); | |
| }); | |
| } | |
| } | |
| public class UrlAliasHandler<T> where T : class, new() | |
| { | |
| public FubuContinuation Execute() | |
| { | |
| return FubuContinuation.TransferTo<T>(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment