Skip to content

Instantly share code, notes, and snippets.

@thecodejunkie
Created April 22, 2012 20:24
Show Gist options
  • Save thecodejunkie/2466652 to your computer and use it in GitHub Desktop.
Save thecodejunkie/2466652 to your computer and use it in GitHub Desktop.
Sample of how you could get rid of the magic string
using Nancy;
using Nancy.Extensions;
public class Home : NancyModuleBase
{
public Home()
{
Get["/"] = parameters => {
return "Hello";
};
Get["/home"] = parameters => {
return Response.AsRedirect(Url.Homepage());
};
}
}
public abstract class NancyModuleBase : NancyModule
{
protected NancyModuleBase()
: this(string.Empty)
{
}
protected NancyModuleBase(string modulePath)
: base(modulePath)
{
this.Url = new Url(this.Context);
}
public Url Url { get; private set; }
}
public class Url
{
private readonly NancyContext context;
public Url(NancyContext context)
{
this.context = context;
}
public string Homepage()
{
return this.context.ToFullPath("~/");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment