While exploring the instance context initializer and call context initializer in WCF I came across the extensible objects in WCF.This extensible object pattern is used for extending the runtime behavior of the existing classes or to add custom state information.In this pattern we have an object which wants to provide facility to extend it’s behavior using other custom objects.So this object is an Extensible Object.The custom objects extending the behaviors are Extensions.This is what is modelled using the three interfaces.
- IExtensibleObject <T> where T is the extensible class.This interface enables an object to provide extension point for custom functionality.This interface has only one readonly property:
- IExtensionCollection<T> Extensions { get; }
- IExtension<T> where T is a type of IExtensibleObject<T>.It enables to extend an object of type IExtensibleObject through aggregation.This interface defines two methods:
- Attach – Enables an extension object to find out when it has been aggregated.This is called when an extension object is added to the IExtensibleObject<T>.Extensions collection
- Detach – Enables an extension object to find out when it is no longer aggregated.This is called when an extension object is removed from the IExtensibleObject<T>.Extensions collection
- IExtensionCollection<T> where T is an IExtension object.
In WCF classes following classes provide extension points by implementing the IExtensibleObject interface.
- System.ServiceModel.ServiceHostBase
- System.ServiceModel.InstanceContext
- System.ServiceModel.OperationContext
- System.ServiceModel.IContextChannel
in my next post while discussing about context initializers I will use extensible object in the examples.But this pattern can be used outside WCF as well.This is explained by a nice example in Prajeesh’s blog.
http://blogsprajeesh.blogspot.com/2008/10/using-extensible-object-pattern-to.html

