未调用自定义 Nancy 引导程序

Custom Nancy bootstrapper not being called

我正在构建一个基于 Nancy 的应用程序,它使用 NancyHost 作为嵌入式 Web 服务器。

我也在尝试通过创建自定义引导程序来提供一些静态内容,如他们的文档 here 中所述。 但是,我看到的问题是这个自定义引导程序 class 从未实例化并且从未调用过 ConfigureConventions 方法。是否有任何我必须执行的特定操作才能确保此自定义引导程序已注册?

下面的自定义引导程序代码:

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);
        }
    }
}

您的引导程序是否在另一个程序集中?

请检查 IncludeInNancyAssemblyScanning 在 Documentation

事实证明,我必须在 NancyHost 构造函数中传递对我的 CustomBootstrapper 的引用。

var host = new NancyHost(new Uri(JsonHelper.URL), new CustomBootstrapper(), config);
host.Start();