使用OWIN时为Nancy提供自定义rootpath

时间:2013-10-01 14:40:29

标签: nancy

我有一个sample application,展示了如何在node.js上托管Nancy。

要做到这一点,我需要更改根路径。我最终得到了类似的东西:

public class Startup
{
    public static void Configuration(IAppBuilder app)
    {
        string rootpath = app.Properties["node.rootpath"] as string;

        app.UseNancy(options => options.Bootstrapper = new NodeBootstrapper(rootpath));
    }
}

public class NodeRootPathProvider : IRootPathProvider
{
    private string rootpath;

    public NodeRootPathProvider(string rootpath)
    {
        this.rootpath = rootpath;
    }

    public string GetRootPath()
    {
        return this.rootpath;
    }
}

public class NodeBootstrapper : DefaultNancyBootstrapper
{
    private string rootpath;

    public NodeBootstrapper(string rootpath)
        : base()
    {
        this.rootpath = rootpath;
    }

    protected override IRootPathProvider RootPathProvider
    {
        get { return new NodeRootPathProvider(this.rootpath); }
    }
}

有没有办法简化这个?

0 个答案:

没有答案