在工作中,我们需要一个小型应用程序,并决定对该项目也测试一些我们并不真正熟悉的东西。
我从一个控制台应用程序开始,使用 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() 添加到参数中