Beispiel #1
0
        private InstanceProducer BuildMutableCollectionProducerFromControlledCollection(
            Type serviceType, Type elementType, MutableCollectionType collectionType)
        {
            Expression expression =
                this.BuildMutableCollectionExpressionFromControlledCollection(serviceType, elementType);

            // Technically, we could determine the longest lifestyle out of the elements of the collection,
            // instead of using Transient here. This would make it less likely for the user to get false
            // positive Lifestyle Mismatch warnings. Problem with that is that trying to retrieve the
            // longest lifestyle might cause the array to be cached in a way that is incorrect, because
            // who knows what kind of lifestyles the used created.
            Registration registration =
                new ExpressionRegistration(expression, serviceType, Lifestyle.Transient, this);

            return(new InstanceProducer(serviceType, registration)
            {
                IsContainerAutoRegistered = !this.GetAllInstances(elementType).Any()
            });
        }
Beispiel #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));
            }
        }