Skip to content

Setup selfhosted WCF services

Scott Xu edited this page Apr 7, 2014 · 6 revisions

Selfhosting of WCF services is based on Ninject.Web.Common.SelfHosting. To use it you have to follow the documentation of this package.

Once this is done you can define WCF service configurations using the static methods on NinjectWcfConfiguration. The simplest variant is to specify what factory shall by used for a service type

    NinjectWcfConfiguration.Create<TimeService, NinjectServiceSelfHostFactory>();
    NinjectWcfConfiguration.Create<TimeWebService, NinjectWebServiceSelfHostFactory>();

There are two factories you can choose from:

  • NinjectServiceSelfHostFactory is for normal web services
  • NinjectWebServiceSelfHostFactory can be used for REST web services

Configure the service host using code

There are other overloads that allow to configure the service host by specifying an action that is executed when the service host is created.

    NinjectWcfConfiguration.Create<TimeService, NinjectServiceSelfHostFactory>(
        servicehost => servicehost.AddServiceEndpoint( ... ));

Configure the service host using App.config

The WCF services can be configured using the usual way in the section of the App.config

Clone this wiki locally