1

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

我从一个控制台应用程序开始,使用 topshelf 通过 nancy 自托管包托管 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) 发生错误;一旦我将新的 Bootstrapper() 添加到参数中

4

1 回答 1

1

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

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

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

于 2018-01-04T16:24:47.993 回答