I have a service that is hosted in WAS. I am trying to inject this service with dependencies, but have been having trouble finding where to do this. In a WCF service hosted in IIS you can use the application_onstart event to instantiate the castle container, but this isn't available in my scenario. So, I am trying to create a custom host factory like so:
public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses)
{
container = new WindsorContainer();
container.Register(Component.For<IMyDependency>().ImplementedBy<MyDependency>());
DefaultServiceHostFactory.RegisterContainer(container.Kernel);
var service = container.Resolve(constructorString);
ServiceHost serviceHost = new ServiceHost(service, baseAddresses);
return serviceHost;
}
This works fine with singleton WCF services, but how do you get this to work with per-call? With non singleton services it is expecting a type to be passed to the ServiceHost constructor rather than an actual service. However, if I do this then when the service spins up it looks for a parameterless constructor only, not the DI version.
Any ideas on how to get this all working?
Thanks