internal bool TryGetInternal(Type requiredType, out DependencyDefinition definition)
        {
            string key = requiredType.FullName;

            if (definitionByKey.TryGetValue(key, out definition))
            {
                definition = definition.Clone(true);
                return(true);
            }

            foreach (List <DependencyDefinition> items in definitionByScopeName.Values)
            {
                foreach (DependencyDefinition item in items)
                {
                    if (item.RequiredType == requiredType)
                    {
                        definition = item.Clone(false);
                        return(true);
                    }
                }
            }

            if (parentCollection != null)
            {
                if (parentCollection.TryGetInternal(requiredType, out definition))
                {
                    return(true);
                }
            }

            definition = null;
            return(false);
        }
        public object Resolve(Type requiredType)
        {
            DependencyDefinition definition;

            if (!definitions.TryGetInternal(requiredType, out definition))
            {
                definitions.Add(requiredType, DependencyLifetime.Transient, requiredType);
                if (!definitions.TryGetInternal(requiredType, out definition))
                {
                    throw Ensure.Exception.InvalidOperation("Unnable to create registration for type '{0}'.", requiredType.FullName);
                }
            }

            if (definition.IsResolvable)
            {
                return(Build(definition));
            }

            throw Ensure.Exception.NotResolvable(requiredType);
        }