Using Unity Dependency Injection with WCF services

前端 未结 3 1150
醉酒成梦
醉酒成梦 2020-12-15 09:06

I have the following after doing some research on other questions:

MyServiceHost:

public class MyServiceHost : ServiceHost
{
    pub         


        
3条回答
  •  半阙折子戏
    2020-12-15 09:30

    The CreateServiceHost method expects an array of Uri instances, so try this instead:

    ServiceHost host = shf.CreateServiceHost(serviceType, new[] { serviceUri });
    

    You can map interfaces to types in either XML or code, but I'd recommend code, since XML has too high a maintenance overhead.

    The Main method is an excellent Composition Root, but if you want to configure the container at that level, you'll need to pass it from the Main method to MyServiceHostFactory - which is perfectly fine when you host the service in a console application, but will not work if you want to host it in IIS, where MyServiceHostFactory should be the Composition Root, since IIS requires a default constructor.

提交回复
热议问题