IInstanceContextProvider Interface

Definition

Implement to participate in the creation or choosing of a InstanceContext object, especially to enable shared sessions.

public interface class IInstanceContextProvider
public interface IInstanceContextProvider
type IInstanceContextProvider = interface
Public Interface IInstanceContextProvider

Remarks

Implement the IInstanceContextProvider interface to provide the appropriate System.ServiceModel.InstanceContext object to the system. Typically, this interface is implemented to support shared sessions, enable service instance pooling, control lifetimes of service instances, or to group contexts among clients.

For example, to implement sharing, insert a custom IInstanceContextProvider to decide which session or call from a client is associated with which InstanceContext object. For an example that demonstrates the sharing of instance contexts, see InstanceContextSharing.

Note

When an IInstanceContextProvider is inserted into Windows Communication Foundation (WCF), the normal property that controls the creation of InstanceContext objects (the ServiceBehaviorAttribute.InstanceContextMode property) is no longer checked and has no effect.

A more generic mechanism by which you can initialize InstanceContext objects when created (for example, to attach custom extensions to each InstanceContext) is the System.ServiceModel.Dispatcher.IInstanceContextInitializer.

Methods

GetExistingInstanceContext(Message, IContextChannel)

Called when a new message is received.

InitializeInstanceContext(InstanceContext, Message, IContextChannel)

Called when null is returned from the GetExistingInstanceContext(Message, IContextChannel) method.

IsIdle(InstanceContext)

Called when all InstanceContext activities have completed to enable implementers to prevent the InstanceContext from being recycled.

NotifyIdle(InstanceContextIdleCallback, InstanceContext)

Called when the IsIdle(InstanceContext) method returns false to enable implementers to provide a callback to notify WCF when the InstanceContext object is finished.

Applies to