I am trying to bend my mind around WCF and Dependency Injection is a point that confuses me a bit.
My question is basically: Does WCF support Dependency Injection out of the box, or does one have to rely on some external framework for that?
If there is a way to do this using nothing but WCF, could you give me a link to a simple example?
WCF says nothing about dependency injection as such. Usually you need to use a framework like Unity or StructureMap or Ninject or Castle Windsor to do it.
There are other messages here about how to do it.
Check out this blog post by Jimmy Bogard about hooking StructureMap into the WCF integration points that allows him to not have constructor-less service constructors. I know that you're looking for a non-DI Framework, so if you use the approaches provided in the links from Peter K's comment to his answer and combine the roll-you-own DI container with WCF's integration points with IInstanceProvider
and IServiceBehavior
as described by Jimmy, you should have a DI solution for WCF that doesn't use a third-party DI framework.
It's definitely isn't a 5-minute exercise and will require a bit of code, but hopefully this helps. Let me know if you have questions and I'll update this response. Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With