I am trying to connect WCF to dependency injection. All the examples I found are based on the assumption that you are either using the .svc service (ServiceHostFactory) or using app.config to configure the container. Other examples are also based on the fact that the container is passed to classes.
I need a solution where the container is not being passed (not closely related to Unity). Where I do not use the configuration file to configure the container and where I use self-service.
The problem is that, as I see it, ServiceHost uses the service implementation type as a parameter, and what does it do to use InstanceProvider?
The solution I have come to at the moment is to register the ServiceHost (or specialization) in a type register with a name (for example, container.RegisterInstance<Type>("ServiceName", typeof(Service); ).
And then container.RegisterType<UnityServiceHost>(new InjectionConstructor(new ResolvedParameter<Type>("ServiceName"))); to register a ServiceHost.
Are there any better solutions? I, probably, in my assumptions.
Best wishes,
Michael
source share