Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF service instantiation via IoC container

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.

like image 786
jonsequitur Avatar asked Dec 29 '08 23:12

jonsequitur


People also ask

What does IoC container do?

IoC container is a framework for implementing automated dependency injection. It contains object creation for the longer ways to use and injects dependencies within the class.

What is the use of IoC container in C#?

IoC means that one code calls another; DI goes beyond that and implements IoC by using composition. A DI or IoC container needs to instantiate objects (dependencies) and provide them to the application. To do so, it must deal with constructor injection, setter injection, and interface injection.

What is IoC configuration?

Configuration is a container agnostic configuration of dependency injection. IoC. Configuration is a wrapper around popular IoC containers, with additional functionality (see below). Currently Ninject and Autofac are supported through the usage of Nuget extension packages IoC.


1 Answers

Short answer - yes it may.

Please take a look at Castle WCF intergration. It let's you use Castle Windsor for WCF, what gives you much more powerful capabilities than just injecting dependencies. It's best to use the trunk version found here. There's not much documentation on it, but take a look at tests. They are easy to follow and will be a good sample code for you. WCF facility let's you do exactly those kinds of thinkgs you're asking about.

like image 130
Krzysztof Kozmic Avatar answered Sep 30 '22 19:09

Krzysztof Kozmic