The following example shows a function that can be used in a Windows Service for setting up Ninject to create ServiceHost instances in a self-hosting scenario:
private static NinjectServiceHost CreateServiceHost(IKernel standardKernel, Type serviceType) { if (standardKernel == null) { throw new ArgumentNullException("standardKernel"); } if (serviceType == null) { throw new ArgumentNullException("serviceType"); } NinjectServiceHost ninjectServiceHost = new NinjectServiceHost( serviceBehavior: new NinjectServiceBehavior( instanceProviderFactory: type => new NinjectInstanceProvider(type, standardKernel), requestScopeCleanUp: new WcfRequestScopeCleanup(true) ), serviceType: serviceType ); return ninjectServiceHost; }
This function will be good enough to boot strap your services in your Windows ServiceBase
implementation in the vast majority of cases. You need only pass in your pre-configured
IKernel instance and the Type of the WCF Service implementation.
No comments:
Post a Comment