private InstanceProducer TryBuildInstanceProducerForCollection(Type serviceType) { if (!Helpers.IsGenericCollectionType(serviceType)) { return(null); } // We don't auto-register collections for ambiguous types. if (Helpers.IsAmbiguousOrValueType(serviceType.GetGenericArguments()[0])) { return(null); } lock (this.emptyAndRedirectedCollectionRegistrationCache) { InstanceProducer producer; // We need to cache these generated producers, to prevent getting duplicate producers; which // will cause (incorrect) diagnostic warnings. if (!this.emptyAndRedirectedCollectionRegistrationCache.TryGetValue(serviceType, out producer)) { producer = this.TryBuildCollectionInstanceProducer(serviceType) ?? this.TryBuildEmptyCollectionInstanceProducerForEnumerable(serviceType); this.emptyAndRedirectedCollectionRegistrationCache[serviceType] = producer; } return(producer); } }