Ninject WCF引导程序注册多个服务

我有一个问题让wcf扩展与多个自我主机引导程序一起工作。 有一个我的服务是由ninject罚款(每次调用)创建的,但是当我添加另一个我得到一个异常,ChannelDispatcher无法打开它的IChannelListener时,内部异常指出注册已经为URI'net.tcp:/ /本地主机:901 /为MyService”。

我的注册码如下所示:

var myService= NinjectWcfConfiguration.Create<MyService, NinjectServiceSelfHostFactory>();
_myServiceHost= new NinjectSelfHostBootstrapper(() => _kernel, myService);

var myService2= NinjectWcfConfiguration.Create<MyService2, NinjectServiceSelfHostFactory>();
_myService2Host= new NinjectSelfHostBootstrapper(() => _kernel, myService2);

_myServiceHost.Start();
_myService2Host.Start();

两个服务在配置文件中都有正确的部分,并且它们都具有不同端口的不同端点URI。 如果我手动将所有这一切连接起来,相同的配置工作正常。

有没有人有线索? 有点难倒...

干杯


我刚才遇到这个问题,解决方案是在其params中包含一个包含所有配置的Bootstrapper:

var myService= NinjectWcfConfiguration.Create<MyService, NinjectServiceSelfHostFactory>();
var myService2= NinjectWcfConfiguration.Create<MyService2, NinjectServiceSelfHostFactory>();

_myServicesHost= new NinjectSelfHostBootstrapper(() => _kernel, myService, myService2);

_myServicesHost.Start();

另一种选择是为每个NinjectSelfHostBootstrapper实例使用单独的内核

var myService= NinjectWcfConfiguration.Create<MyService, NinjectServiceSelfHostFactory>();
_myServiceHost= new NinjectSelfHostBootstrapper(() => new StandardKernel(YourInjectionModule), myService);

var myService2= NinjectWcfConfiguration.Create<MyService2, NinjectServiceSelfHostFactory>();
_myService2Host= new NinjectSelfHostBootstrapper(() => new StandardKernel(YourInjectionModule), myService2);

_myServiceHost.Start();
_myService2Host.Start();

另外,当你处置NinjectSelfHostBootstrapper时, _myServiceHost.Dispose()的内核也会被丢弃。 所以如果你在其他地方使用你的内核,你会遇到问题。

链接地址: http://www.djcxy.com/p/72463.html

上一篇: Ninject WCF bootstrapper registering multiple services

下一篇: LEVEL EXCEPTION in Android Studio