This is a mirror of official site: http://jasper-net.blogspot.com/

WCF Extensibility – Initializers (instance context, channel, call context)

| Wednesday, February 15, 2012
This post is part of a series about WCF extensibility points. For a list of all previous posts and planned future ones, go to the index page.

And we’re reaching the end of this series. To close it, I’ll cover some of the lesser used extensibility points in WCF, which would be too short for a full post. This time I’ll cover the “initializer” interfaces, which can be used to, well, initialize some component of the WCF runtime. Those are the IInstanceContextInitializer, ICallContextInitializer and IChannelInitializer, which will be covered in detail below.

And since there will be multiple samples in this post, the usual disclaimer goes ahead: they are simple samples for illustrating the topics of this post, not production-ready code. I tested them for a few contracts and they worked, but I cannot guarantee that they will work for all scenarios – please let me know if you find a bug or something missing. There are some shortcuts I did in them to make the sample smaller, such as not using real resource files in the call context initializer sample, and, as usual, error checking has been kept to a minimum.


IInstanceContextInitializer

The example from the previous post showed how we can completely control the instance context life cycle with the IInstanceContextProvider interface. There are some scenarios, however, where all we want is to simply perform some initialization code when a new instance context is created – essentially, only implement the InitializeInstanceContext method in the instance context provider. Such scenarios can involve attaching an extension to the instance context, or possibly doing some custom throttling. For those cases, having to implement the whole instance context provider is a lot of work, so for this scenario WCF also provides (yet) another extensibility point, the IInstanceContextInitializer interface, which is called whenever a new instance context is created. The interface declaration is shown below.

    public interface IInstanceContextInitializer
    {
        void Initialize(InstanceContext instanceContext, Message message);
    }


Read more: Carlos' blog
QR: wcf-extensibility-initializers-instance-context-channel-call-context.aspx

Posted via email from Jasper-net

0 comments: