/// <summary> /// Registers a collection of <paramref name="registrations"/>, whose instances will be resolved lazily /// each time the resolved collection of <paramref name="serviceType"/> is enumerated. /// The underlying collection is a stream that will return individual instances based on their /// specific registered lifestyle, for each call to <see cref="IEnumerator{T}.Current"/>. /// The order in which the types appear in the collection is the exact same order that the items were /// registered, i.e the resolved collection is deterministic. /// </summary> /// <param name="serviceType">The base type or interface for elements in the collection. This can be /// an a non-generic type, closed generic type or generic type definition.</param> /// <param name="registrations">The collection of <see cref="Registration"/> objects whose instances /// will be requested from the container.</param> /// <exception cref="ArgumentNullException">Thrown when one of the supplied arguments is a null /// reference (Nothing in VB). /// </exception> /// <exception cref="ArgumentException">Thrown when <paramref name="registrations"/> contains a null /// (Nothing in VB) element or when <paramref name="serviceType"/> is not assignable from any of the /// service types supplied by the given <paramref name="registrations"/> instances. /// </exception> public void RegisterCollection(Type serviceType, IEnumerable <Registration> registrations) { Requires.IsNotNull(serviceType, "serviceType"); Requires.IsNotNull(registrations, "registrations"); // Make a copy for performance and correctness. registrations = registrations.ToArray(); Requires.DoesNotContainNullValues(registrations, "registrations"); Requires.AreRegistrationsForThisContainer(this, registrations, "registrations"); Requires.ServiceIsAssignableFromImplementations(serviceType, registrations, "registrations", typeCanBeServiceType: true); Requires.OpenGenericTypesDoNotContainUnresolvableTypeArguments(serviceType, registrations, "registrations"); this.RegisterCollectionInternal(serviceType, registrations); }
private ContainerControlledCollection <TService> CreateInternal <TService>( IEnumerable <Registration> registrations) where TService : class { Requires.IsNotAnAmbiguousType(typeof(TService), nameof(TService)); Requires.IsNotNull(registrations, nameof(registrations)); Requires.DoesNotContainNullValues(registrations, nameof(registrations)); Requires.AreRegistrationsForThisContainer(this.container, registrations, nameof(registrations)); Requires.ServiceIsAssignableFromImplementations(typeof(TService), registrations, nameof(registrations), typeCanBeServiceType: true); Requires.OpenGenericTypesDoNotContainUnresolvableTypeArguments(typeof(TService), registrations, nameof(registrations)); var collection = new ContainerControlledCollection <TService>(this.container); collection.AppendAll(registrations); this.RegisterForVerification(collection); return(collection); }