Exemple #1
0
        private InstanceProducer TryBuildInstanceProducerForStream(Type serviceType)
        {
            if (!Types.IsGenericCollectionType(serviceType))
            {
                return(null);
            }

            // We don't auto-register collections for ambiguous types.
            if (Types.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))
                {
                    // This call might lock the container
                    producer = this.TryBuildStreamInstanceProducer(serviceType);

                    this.emptyAndRedirectedCollectionRegistrationCache[serviceType] = producer;
                }

                return(producer);
            }
        }
Exemple #2
0
        private InstanceProducer BuildInstanceProducerForMutableCollectionType(
            Type serviceType, Type elementType, MutableCollectionType type)
        {
            // We don't auto-register collections for ambiguous types.
            if (Types.IsAmbiguousOrValueType(elementType))
            {
                return(null);
            }

            // GetAllInstances locks the container
            if (this.GetAllInstances(elementType) is IContainerControlledCollection)
            {
                return(this.BuildMutableCollectionProducerFromControlledCollection(serviceType, elementType, type));
            }
            else
            {
                return(this.BuildMutableCollectionProducerFromUncontrolledCollection(serviceType, elementType));
            }
        }