Skip to content

Instantly share code, notes, and snippets.

@emiaj
Created August 20, 2012 19:03
Show Gist options
  • Select an option

  • Save emiaj/3406752 to your computer and use it in GitHub Desktop.

Select an option

Save emiaj/3406752 to your computer and use it in GitHub Desktop.
[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