Declares methods that provide a service object or recycle a service object for a Windows Communication Foundation (WCF) service.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
Thetype exposes the following members.
Implement the interface to control the creation and recycling of service objects when one is requested or disposed by an InstanceContext object.
Once the interface is implemented, you must assign your custom instance provider object to the InstanceProvider property using either an endpoint behavior (a IEndpointBehavior object) or a contract behavior (a IContractBehavior object).
If the insertion mechanism is an endpoint behavior you can also implement a BehaviorExtensionElement object that can insert your custom behavior using a configuration file. If the insertion mechanism is a contract behavior, you can insert the behavior programmatically prior to the opening of the service host or you can implement a custom attribute. (For an example of the contract behavior approach, see the Example section.)
has two methods, GetInstance and ReleaseInstance. These methods are typically implemented to create service objects using a non-default constructor or to initialize or dispose of some state related to the lifetime of the object. Service object pooling is one example of custom functionality.
There are two ways to cause an InstanceContext object to release a service object before the InstanceContext is closed. The first method is to set the ReleaseInstanceMode to AfterCall or BeforeAndAfterCall. The second method is to call the ReleaseServiceInstance method. If this is done, the InstanceContext calls the ReleaseInstance method on the dispatcher's instance provider. If a new message arrives after the instance has been released, WCF creates a new instance using the GetInstance method.
The following code example shows how to implement that provides "singleton" behavior; it always returns the same service instance and does not recycle it.
The following code example shows how to implement a custom attribute that implements IContractBehavior to insert the custom service instance provider. It also implements IContractBehaviorAttribute, which binds its use to a specific contract.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.