/// <summary>
        /// Tries to return all definitions bound to the <paramref name="scopeName"/>.
        /// </summary>
        /// <param name="scopeName">Scope name to find definitions for.</param>
        /// <param name="definitions">Enumerations for scoped definitions for <paramref name="scopeName"/>.</param>
        /// <returns><c>true</c> if such definitions exits (at least one); <c>false</c> otherwise.</returns>
        public bool TryGet(string scopeName, out IEnumerable <DependencyDefinition> definitions)
        {
            List <DependencyDefinition> result;

            if (storage.TryGetValue(scopeName, out result))
            {
                definitions = result;

                IEnumerable <DependencyDefinition> parentResult;
                if (parentCollection != null && parentCollection.TryGet(scopeName, out parentResult))
                {
                    definitions = Enumerable.Concat(result, parentResult);
                }

                return(true);
            }

            if (parentCollection != null)
            {
                return(parentCollection.TryGet(scopeName, out definitions));
            }

            definitions = null;
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Copies definitions from ancestors for current scope.
        /// </summary>
        /// <param name="mappings">Ancestor definitions.</param>
        /// <param name="scopeName">Current scope name.</param>
        private void CopyFromParentScope(MapperCollection mappings, string scopeName)
        {
            IEnumerable <DependencyDefinition> scopeMappings;

            if (mappings.TryGet(scopeName, out scopeMappings))
            {
                foreach (DependencyDefinition model in scopeMappings)
                {
                    Add(model);
                }
            }
        }