I have a service configured with following attributes
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
public class UserService : IUserServiceContract
{}
Should I use in this scenario locking mechanism for methods implemented in the service?
If yes, is this the proper implementation ?
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
public class UserService : IUserServiceContract
{
private readonly object LockObject = new object();
public Object1 GetObject1()
{
lock (LockObject)
{
using (var ob = new Object1)
{
return ob.Get();
}
}
}
public Object2 GetObject2()
{
lock (LockObject)
{
using (var ob = new Object2)
{
return ob.Get();
}
}
}
}