nancy selfhost,带有 dryioc 和 bootstrapper -> Method not found 异常

nancy selfhost, with dryioc and bootstrapper -> Method not found exception

在工作中我们需要一个小应用程序,因此决定也为这个项目测试一些我们不太熟悉的东西。

我从一个控制台应用程序开始,使用 topshelf 通过 nancy selfhosting 包来托管 nancy。 所有这些都有效。

现在我想将 DryIoc 容器连接到 nancy 引导程序中,但出现以下错误:

System.MissingMethodException
  HResult=0x80131513
  Message=Method not found: 'DryIoc.Rules DryIoc.Rules.With(DryIoc.FactoryMethodSelector, DryIoc.ParameterSelector, DryIoc.PropertiesAndFieldsSelector, Boolean)'.
  Source=Nancy.Bootstrappers.DryIoc
  StackTrace:
   at Nancy.Bootstrappers.DryIoc.DryIocNancyBootstrapper.<GetApplicationContainer>b__0(Rules rules)
   at DryIoc.Container..ctor(Func`2 configure, IScopeContext scopeContext)
   at Nancy.Bootstrappers.DryIoc.DryIocNancyBootstrapper.GetApplicationContainer()
   at Nancy.Bootstrapper.NancyBootstrapperBase`1.Initialise()
   at Nancy.Hosting.Self.NancyHost..ctor(INancyBootstrapper bootstrapper, HostConfiguration configuration, Uri[] baseUris)
   at Nancy.Hosting.Self.NancyHost..ctor(Uri baseUri, INancyBootstrapper bootstrapper, HostConfiguration configuration)
   at Segrey.Licensing.Web.WebService.Start() in I:\git projects\Segrey.Licensing\Segrey.Licensing.Web\WebService.cs:line 21
   at Segrey.Licensing.Service.Program.<>c.<CreateHost>b__1_2(WebService ls) in I:\git projects\Segrey.Licensing\Segrey.Licensing.Service\Program.cs:line 26
   at Topshelf.ServiceConfiguratorExtensions.<>c__DisplayClass2_0`1.<WhenStarted>b__0(T service, HostControl control)
   at Topshelf.Builders.DelegateServiceBuilder`1.DelegateServiceHandle.Start(HostControl hostControl)
   at Topshelf.Hosts.ConsoleRunHost.Run()

我的引导程序:空的,还没有注册,因为我首先想测试一下 在让它变得更复杂之前

public class Bootstrapper : DryIocNancyBootstrapper
{
    protected override void ApplicationStartup(IContainer container, IPipelines pipelines)
    {
        //No registrations should be performed in here, however you may
        //resolve things that are needed during application startup.
        base.ApplicationStartup(container, pipelines);
    }

    protected override void ConfigureApplicationContainer(IContainer container)
    {
        //Perform registation that should have an application lifetime
        base.ConfigureApplicationContainer(container);
    }

    protected override void ConfigureRequestContainer(IContainer container, NancyContext context)
    {
        //Perform registrations that should have a request lifetime
        base.ConfigureRequestContainer(container, context);
    }

    protected override void RequestStartup(IContainer container, IPipelines pipelines, NancyContext context)
    {
        // No registrations should be performed in here, however you may
        // resolve things that are needed during request startup.
        base.RequestStartup(container, pipelines, context);
    }
}

在我的 .Start 服务方法中,通过分配引导程序的 topshelf

public void Start()
{
    var hostConfig = new HostConfiguration() { UrlReservations = new 
    UrlReservations { CreateAutomatically = true } };
    var uri = new Uri(_hostUrl);
    _nancyHost = new NancyHost(uri, new Bootstrapper(), hostConfig);
    _nancyHost.Start();
}

new NancyHost(uri, new Bootstrapper(), hostConfig) 发生错误;一旦我将 new Bootstrapper() 添加到参数

听起来像是版本问题。检查您的 .config 文件以了解 dryioc 的绑定重定向。

似乎 DryIocNancyBootstrapper 认为它使用的是 DryIOC 的 X 版本,但它使用的是 Y 版本(由于绑定重定向),它没有该方法(要么已被删除,要么是旧版本还没有它的版本)。

找出 DryIocNancyBootstrapper 想要的版本(即上例中的版本 X)并引用该版本。