Dependency Injection in WCF Services

I'm trying to bow my head around WCF, and Dependency Injection is a point that bothers me a bit.

My main question is: Does WCF support Injection Dependency out of the box, or do you need to rely on some external framework for this?

If there is a way to do this using only WCF, could you give me a link to a simple example?

+7
source share
3 answers

Check out Jimmy Bogard's blog post for linking StructureMap to WCF integration points, which allows it to have no constructors without a constructor. I know that you are looking for a non-DI Framework, so if you use the approaches given in the links from Peter K's comment to his answer and combine your own DI container with WCF integration points with IInstanceProvider and IServiceBehavior , as described by Jimmy, you should have a DI for WCF that does not use a third-party DI infrastructure.

This is definitely not a 5 minute exercise and will require a bit of code, but hopefully it helps. Let me know if you have any questions and I will update this answer. Good luck

+7
source

WCF says nothing about dependency injection. Usually you need to use a framework like Unity or StructureMap or Ninject or Castle Windsor to do this.

Other posts here on how to do this .

+1
source

I have WCF dependency injection support for Unity in my Toolkit - http://neovolve.codeplex.com/releases/view/19004 . The documentation in the package shows how to connect it. Being open source, you can modify it to use any IOC container that you use if it is not Unity.

+1
source

All Articles