Castle WCF Windsor and WAS

I have a service hosted in WAS. I am trying to use this service with dependencies, but I am having trouble finding where to do it. In a WCF service hosted in IIS, you can use the application_onstart event to instantiate a lock container, but this is not possible in my script. So, I am trying to create my own factory host as follows:

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 great with singleton WCF services, but how can you use this for every call? When using non singleton services, it is expected that the type will be passed to the ServiceHost constructor, and not to the actual service. However, if I do this, then when the service is spinning, it only looks for a constructor with no parameters, and not a DI version.

Any ideas on how to make this all work?

thanks

+3
1
+2

Source: https://habr.com/ru/post/1715186/


All Articles