Ninject WCF bootloader registering multiple services

I had a problem with wcf extensions working with multiple boot nodes of the host itself. Ninject fine is created with one of my services (per call), but when I add another, I get an exception that ChannelDispatcher cannot open its IChannelListener, an internal exception indicates that registration is already used for URI 'net.tcp: // local :. 901 / MyService

My registration code is as follows:

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 configuration file, and both have different endpoint URIs with different ports. The same configuration works fine if I do everything manually.

Does anyone have a key? Bit......

Greetings

+7
c # ninject wcf
source share
2 answers

I ran into this problem just now, the solution is to have one Bootstrapper with all the configurations in its parameters:

 var myService= NinjectWcfConfiguration.Create<MyService, NinjectServiceSelfHostFactory>(); var myService2= NinjectWcfConfiguration.Create<MyService2, NinjectServiceSelfHostFactory>(); _myServicesHost= new NinjectSelfHostBootstrapper(() => _kernel, myService, myService2); _myServicesHost.Start(); 
+4
source share

Another alternative is to use a separate kernel for each instance of 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(); 

In addition, when you install NinjectSelfHostBootstrapper _myServiceHost.Dispose() , its kernel will also be removed. Therefore, if you use your kernel elsewhere, you will run into problems.

0
source share

All Articles