[Filed under old stuff.]
Microsoft has provided a large number of seams/hooks into WCF so that we can extend it. I believe that the two most powerful are the IInstanceProvider and IOperationInvoker.
IInstanceProvider can be implemented in a class that specifies how WCF creates the instance of the service requested. By default, WCF creates an instance of the service by invoking its parameterless constructor. If you have a case in which you need to do other things when that instance is created - say you want to inject dependencies into it - you have to create your own instance provider. Additionally, in order to make the whole thing work you have to create three other custom classes - a custom behavior responsible for assigning your custom instance provider to the InstanceProvider property of the DispatchRuntime, a custom service host that applies the custom behavior, and finally a custom service host factory that builds the custom service host. This may sound like a lot, but it really is fairly straightforward. The best example of this I've seen can be found as Los Techies.
IOperationInvoker allows you to decorate existing operations with additional responsibilities at runtime. A really good example (within a really good article) can be found over at MSDN. Another example - this one allows WCF to call COM objects within STA (single apartment threads): Scott Seely's Blog.
Monday, August 31, 2009
Subscribe to:
Posts (Atom)