Can the WCF runtime be made to instantiate a service via an IoC container rather than via its usual process? (Also, given a potential clash between the container’s lifestyle configuration for the type and the service’s InstanceContextBehavior, would this approach be a terrible idea?)
I’m aware that I might be asking the wrong question altogether. My objective is an AOP approach via method interception facilities provided by the container (for example, method enter/exit logging, perf counting, and call throttling, all involving logic and dependencies that I do not want to insert into my service implementation). I imagine WCF provides other ways to approach this, so I would also be curious to hear other recommended approaches.
Yes, heres implementations using both ObjectBuilder and Spring.NET (and more if you follow the links!):
http://www.infoq.com/news/2008/01/wcf-di
Can’t comment on lifestyle and instance context behavior interaction though.
As for more WCF-specific approaches, leveraging WCFs behaviors concept (as the above example does) may also be useful. There are several different types, heres a starting point:
http://mehranikoo.net/CS/archive/2007/02/22/WCFBehaviours.aspx
Cheers,
Matt