I would like to pass values into the constructor on the class that implements my service.
However ServiceHost only lets me pass in the name of the type to create, not what arguments to pass to its contrstructor.
I would like to be able to pass in a factory that creates my service object.
What I have found so far:
- WCF Dependency Injection Behavior which is more than what I am looking for and seems to be over-complex for my needs.
You’ll need to implement a combination of custom
ServiceHostFactory,ServiceHostandIInstanceProvider.Given a service with this constructor signature:
Here’s an example that can spin up MyService:
Register MyServiceHostFactory in your MyService.svc file, or use MyServiceHost directly in code for self-hosting scenarios.
You can easily generalize this approach, and in fact some DI Containers have already done this for you (cue: Windsor’s WCF Facility).