nancy selfhost,with dryioc和bootstrapper - >方法未找到异常

时间:2018-01-04 15:04:11

标签: nancy topshelf dryioc

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

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

现在我想将DryIoc容器连接到nancy bootstrapper中,并出现以下错误:

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

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

1 个答案:

答案 0 :(得分:1)

听起来像版本问题。检查.config文件以获取dryioc的绑定重定向。

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

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