I am trying to get the Dispose method in my IDisposable WCF service, called when using Ninject NinjectServiceHost, with no luck. Then I downloaded the sample code Ninject.extensions.WCF and tried to call the IDisposable TimeService Dispose () method, but it was not called either.
The service is created correctly, just the call to Dispose () is not called.
Is this a bug or something that the example code is missing for me?
I created a disabled service and a test node that reproduces this problem. The code is below.
I am using Ninject 3.0.1.10, Ninject.extensions.WCF 3.0.0.5, .net 4.5
ServiceModule.cs code (for setting up bindings)
using Ninject.Modules; namespace TestNinjectWcf { public class ServiceModule : NinjectModule { public override void Load() { Bind<Service1>().ToSelf();
Console test program to start the service.
using System; using Ninject.Extensions.Wcf; using Ninject; using TestNinjectWcf; namespace TestConsole { class Program { static void Main(string[] args) { var kernel = new StandardKernel(new ServiceModule()); var service = kernel.Get<NinjectServiceHost<Service1>>(); service.Open(); Console.WriteLine("Service Started"); Console.ReadKey(); service.Close(); } } }
Service implementation
using System; using System.Diagnostics; using System.ServiceModel; namespace TestNinjectWcf { [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)] public class Service1 : IService1, IDisposable { public Service1() { Debug.WriteLine("Constructor"); } public string GetData(int value) { return string.Format("You entered: {0}", value); } public void Dispose() { Debug.WriteLine("Dispose");
source share