Catel.IoC.ServiceLocator.ResolveTypeFromKnownContainer C# (CSharp) Method

ResolveTypeFromKnownContainer() private method

Resolves the type from a known container.
The is null. The type is not found in any container.
private ResolveTypeFromKnownContainer ( Type serviceType, object tag ) : object
serviceType System.Type Type of the service.
tag object The tag to register the service with. The default value is null.
return object
        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;
            }
        }