Nonhttp WCF services in IIS and Castle Windsor

If you have a wcf service hosted in IIS that is using a binding that isn't based on http wiring (like net.tcp) it with your IoC container requires some additional steps. For this example i'm using Castle Windsor, first install the Castle Windsor WCF integration facility from nuget, that will pull Castle Windsor & their extensions for wcf. If the binding used for the wcf service isn't based on http then the Applicaton_Start method in global.asax.cs won't be called before the service is invoked. This will cause a problem if our serivce has dependecies that need to be injected. To setup the container used to resolve dependencies we create a class in the App_Code folder under the website that has a method with the following signature: public static void AppInitialize() this method will be called before our service is invoked the first time so it is a perfect place to setup our IoC container. A simple registration would look like this
public class AppInit
{
  private static IWindsorContainer _container;
  public static void AppInitialize()
  {
    _container = new WindsorContainer();
    _container.AddFacility();
    _container.Register(Component.For().ImplementedBy());
  }
}
The last thing to do is in the Serivce.svc markup add the castle factory attribute: Factory="Castle.Facilities.WcfIntegration.DefaultServiceHostFactory, Castle.Facilities.WcfIntegration".