Beispiel #1
0
        /// <summary>
        /// Return instances of all registered types requested.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method is useful if you've registered multiple types with the same
        /// <see cref="Type"/> but different names.
        /// </para>
        /// <para>
        /// Be aware that this method does NOT return an instance for the default (unnamed) registration.
        /// </para>
        /// </remarks>
        /// <param name="t">The type requested.</param>
        /// <returns>Set of objects of type <paramref name="t"/>.</returns>
        public override IEnumerable <object> ResolveAll(Type t)
        {
            List <string> names = new List <string>(registeredNames.GetKeys(t));

            foreach (string name in names)
            {
                yield return(Resolve(t, name));
            }
        }
        public IEnumerable <string> GetKeys(Type t)
        {
            var keys = Enumerable.Empty <string>();

            if (parent != null)
            {
                keys = keys.Concat(parent.GetKeys(t));
            }

            if (registeredKeys.ContainsKey(t))
            {
                keys = keys.Concat(registeredKeys[t]);
            }

            return(keys);
        }
Beispiel #3
0
        private void FillTypeRegistrationDictionary(IDictionary <Type, List <string> > typeRegistrations)
        {
            if (parent != null)
            {
                parent.FillTypeRegistrationDictionary(typeRegistrations);
            }

            foreach (Type t in registeredNames.RegisteredTypes)
            {
                if (!typeRegistrations.ContainsKey(t))
                {
                    typeRegistrations[t] = new List <string>();
                }

                typeRegistrations[t] =
                    (typeRegistrations[t].Concat(registeredNames.GetKeys(t))).Distinct().ToList();
            }
        }
Beispiel #4
0
        public IEnumerable <string> GetKeys(Type t)
        {
            if (parent != null)
            {
                foreach (string name in parent.GetKeys(t))
                {
                    yield return(name);
                }
            }

            if (!registeredKeys.ContainsKey(t))
            {
                yield break;
            }
            foreach (string name in registeredKeys[t])
            {
                yield return(name);
            }
        }
Beispiel #5
0
 private IEnumerable <string> GetRegisteredNames(Type t)
 {
     return(registeredNames.GetKeys(t).Where(s => !string.IsNullOrEmpty(s)));
 }