private object ResolveTypeFromKnownContainer(Type serviceType, object tag)
{
Argument.IsNotNull("serviceType", serviceType);
lock (_lockObject)
{
var typeRequestInfo = new TypeRequestInfo(serviceType, tag);
if (_currentTypeRequestPath == null)
{
_currentTypeRequestPath = new TypeRequestPath(typeRequestInfo, name: "ServiceLocator");
_currentTypeRequestPath.IgnoreDuplicateRequestsDirectlyAfterEachother = false;
}
else
{
_currentTypeRequestPath.PushType(typeRequestInfo, false);
if (!_currentTypeRequestPath.IsValid)
{
// Reset path for next types that are being resolved
var typeRequestPath = _currentTypeRequestPath;
_currentTypeRequestPath = null;
typeRequestPath.ThrowsExceptionIfInvalid();
}
}
var serviceInfo = new ServiceInfo(serviceType, tag);
var registeredTypeInfo = _registeredTypes[serviceInfo];
object instance = registeredTypeInfo.CreateServiceFunc(registeredTypeInfo);
if (instance == null)
{
ThrowTypeNotRegisteredException(serviceType);
}
if (IsTypeRegisteredAsSingleton(serviceType, tag))
{
RegisterInstance(serviceType, instance, tag, this);
}
CompleteTypeRequestPathIfRequired(typeRequestInfo);
return instance;
}
}