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

use*_*754 7 c# wcf ninject

我遇到一个问题,让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();
Run Code Online (Sandbox Code Playgroud)

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

有没有人在这里有线索?有点难过......

干杯

小智 4

我刚才遇到了这个问题,解决方案是让一个 Bootstrapper 的参数中包含所有配置:

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

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

_myServicesHost.Start();
Run Code Online (Sandbox Code Playgroud)