Instance Provider in WCF ?


Instance providers can be applied to services.
Service: Here are the steps for applying an instance provider to a service.
Declare: Implement the System.ServiceModel.Dispatcher.IInstanceProvider interface:
public class RajInstanceProvider :
IInstanceProvider
{
public object GetInstance(
InstanceContext instanceContext,
Message message)
{
//create the service instance here.
}
public object GetInstance(
InstanceContext instanceContext)
{
//create the service instance here.
}
public void ReleaseInstance(
InstanceContext instanceContext,
object instance)
{
//dispose of the service instance.
}
}
Attach: Implement the ApplyDispatchBehavior() method of the System.ServiceModel.
Description.IEndpointBehavior interface:
public class RajInstanceProvider :
IInstanceProvider,
IEndpointBehavior
{
public void ApplyDispatchBehavior(
ServiceEndpoint serviceEndpoint,
EndpointDispatcher endpointDispatcher)
{
endpointDispatcher.DispatchRuntime.InstanceProvider = this;
}
……..
}
Inform In the code for a Windows Communication Foundation service host, add the instance context provider to the Behaviors collection of a System.ServiceModel.Description.EndpointDescription object:
ServiceHost host = new ServiceHost(typeof(Service));
host.Description.Endpoints[0].Behaviors.Add(
new RajInstanceProvider());

Also you can check out my previous posts on:


Create Page Layout using SharePoint Designer 2010

Hide fields in NewForm, EditForm and DispForm in SharePoint 2010



SharePoint Solutions Project Type Templates in SharePoint 2013

Check out Best Alternative to InfoPath -> Try Now

You May Also like the Following SharePoint Online Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →