You are developing a Windows Communication Foundation (WCF) service to provide an in-memory cache for many Web applications.
The service contract is defined as follows. (Line numbers are included for reference only.)
01 [ServiceContract]
02 public interface IDataCache
03 {
04 …
05 }
06
07
08 public class DataCache : IDataCache
09 {
10 …
11 }
You need to ensure that all users share the cache. Which code segment should you insert at line 07?
A.
[ServiceBehavior(TransactionIsolationLevel = IsolationLevel.RepeatableRead)]
B.
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
C.
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
D.
[ServiceBehavior(TransactionIsolationLevel = IsolationLevel.ReadComitted)]
Explanation:
InstanceContextMode Enumeration
(http://msdn.microsoft.com/en-us/library/system.servicemodel.instancecontextmode.aspx)PerSession A new InstanceContext object is created for each session.
PerCall A new InstanceContext object is created prior to and recycled subsequent to each call. If the channel does not create a session this value behaves as if it were PerCall.
Single Only one InstanceContext object is used for all incoming calls and is not recycled subsequent to the calls. If a service object does not exist, one is created.
B