Ninject WCF bootstrapper registering multiple services

I'm having a problem getting the wcf extensions to work with more than one self host bootstrapper. With one my services are created by ninject fine (per call), but when I add another I get an exception that the ChannelDispatcher is unable to open its IChannelListener, the inner exception states that a registration already eixsts for URI 'net.tcp://localhost:901/MyService'.

My registration code looks like this:

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

Both services have the correct sections in the config file and they both have different endpoint URIs with different ports. The same config works fine if I wire all of this up manually.

Does anyone have a clue here? Bit stumped...

Cheers


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

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

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

_myServicesHost.Start();

Another alternative is to use separate Kernel for each NinjectSelfHostBootstrapper instance

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

Also, when you dispose NinjectSelfHostBootstrapper _myServiceHost.Dispose() its Kernel will also be disposed. So if you use your kernel somewhere else you will run into problems.

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

上一篇: 使操作失败

下一篇: Ninject WCF引导程序注册多个服务