Created
April 22, 2012 20:24
-
-
Save thecodejunkie/2466652 to your computer and use it in GitHub Desktop.
Sample of how you could get rid of the magic string
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
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