/// <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> internal bool TryGetChild(string scopeName, out IEnumerable <DependencyDefinition> definitions) { bool isSucess = false; definitions = Enumerable.Empty <DependencyDefinition>(); // 1) Find registrations from parent. if (parentCollection != null) { IEnumerable <DependencyDefinition> parentResult; if (parentCollection.TryGetChild(String.Empty, out parentResult)) { definitions = Enumerable.Concat(definitions, parentResult); isSucess = true; } if (parentCollection.TryGetChild(scopeName, out parentResult)) { definitions = Enumerable.Concat(definitions, parentResult); isSucess = true; } } // 2) Find registrations from current. List <DependencyDefinition> result; if (definitionByScopeName.TryGetValue(String.Empty, out result)) { definitions = Enumerable.Concat(definitions, result); isSucess = true; } if (definitionByScopeName.TryGetValue(scopeName, out result)) { definitions = Enumerable.Concat(definitions, result); isSucess = true; } if (isSucess) { return(true); } definitions = null; return(false); }
public DependencyDefinitionCollection(string scopeName, InstanceStorage instances, DependencyDefinitionCollection parentCollection) : this(scopeName, instances) { Ensure.NotNull(parentCollection, "parentCollection"); this.parentCollection = parentCollection; IEnumerable <DependencyDefinition> definitions; if (parentCollection.TryGetChild(scopeName, out definitions)) { foreach (DependencyDefinition definition in definitions) { Add(definition.RequiredType, definition.Lifetime, definition.Target); } } }