我正在构建一个基于 Nancy 的应用程序,它使用 NancyHost 作为嵌入式 Web 服务器。
我还尝试通过创建自定义 Bootstrap 来提供一些静态内容,如他们的文档中所述 here . 但是,我看到的问题是这个自定义 Bootstrap 类从未被实例化,并且 ConfigureConventions 方法也从未被调用。是否需要执行任何特定操作才能确保注册此自定义 Bootstrap ?
自定义 Bootstrap 代码如下:
using Nancy;
using Nancy.Conventions;
using System;
namespace Application
{
public class CustomBootstrapper : DefaultNancyBootstrapper
{
protected override void ConfigureConventions(NancyConventions conventions)
{
Console.WriteLine("test");
conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("client", @"client"));
conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("lib", @"lib"));
base.ConfigureConventions(conventions);
}
}
}
请您参考如下方法:
事实证明,我必须在 NancyHost 构造函数中传递对我的 CustomBootstrapper 的引用。
var host = new NancyHost(new Uri(JsonHelper.URL), new CustomBootstrapper(), config);
host.Start();
