2 using System
.Collections
.Generic
;
4 using System
.ServiceModel
;
5 using System
.ServiceModel
.Dispatcher
;
6 using System
.ServiceModel
.Channels
;
8 namespace Microsoft
.ServiceModel
.Samples
10 //This class contains the implementation of an IInstanceProvider
11 //which provides the instances created by the storage manager.
12 class InstanceProvider
: IInstanceProvider
16 public InstanceProvider(Type serviceType
)
18 this.serviceType
= serviceType
;
21 public object GetInstance(InstanceContext instanceContext
)
23 return this.GetInstance(instanceContext
, null);
26 public void ReleaseInstance(InstanceContext instanceContext
, object instance
)
30 public object GetInstance(InstanceContext instanceContext
, Message message
)
32 object instance
= null;
34 InstanceContextExtension extension
=
35 instanceContext
.Extensions
.Find
<InstanceContextExtension
>();
37 string contextId
= extension
.ContextId
;
38 IStorageManager storageManager
= extension
.StorageManager
;
40 //Get the instance from the storage manager.
41 instance
= storageManager
.GetInstance(contextId
, serviceType
);
43 // If the storage manager returns null (which means that there is
44 // no instance available for the given context id) create a new
45 // instance and return it.
48 instance
= Activator
.CreateInstance(serviceType
);