LightInject
LightInject copied to clipboard
PerContainerLifetime speed up
Hi,
PerContainerLifetime.GetInstance()
may be sped up by using local variable:
object result = singleton;
if (result != null)
{
return result;
}
lock (syncRoot)
{
result = singleton;
if (result == null)
{
result = singleton = createInstance();
}
}
return result;
The code tries to minimize the access to the volatile variable.
BTW. why not lock(this)
and remove the syncRoot
?