private InstanceProducer BuildEmptyCollectionInstanceProducerForEnumerable(Type enumerableType) { Type elementType = enumerableType.GetGenericArguments()[0]; var collection = DecoratorHelpers.CreateContainerControlledCollection(elementType, this); var registration = new ExpressionRegistration(Expression.Constant(collection, enumerableType), this); return(new InstanceProducer(enumerableType, registration)); }
private static void DecoratesServiceType(Type serviceType, ConstructorInfo decoratorConstructor, string paramName) { bool decoratesServiceType = DecoratorHelpers.DecoratesServiceType(serviceType, decoratorConstructor); if (!decoratesServiceType) { ThrowMustDecorateServiceType(serviceType, decoratorConstructor, paramName); } }
private Registration BuildContainerControlledRegistration(Type closedServiceType, ContainerControlledItem[] closedGenericImplementations) { IContainerControlledCollection collection = DecoratorHelpers.CreateContainerControlledCollection( closedServiceType, this.Container); collection.AppendAll(closedGenericImplementations); return(DecoratorHelpers.CreateRegistrationForContainerControlledCollection(closedServiceType, collection, this.Container)); }
private static void ThrowMustDecorateBaseType(Type serviceType, ConstructorInfo decoratorConstructor, string paramName) { var validConstructorArgumentTypes = DecoratorHelpers.GetValidDecoratorConstructorArgumentTypes(serviceType, decoratorConstructor); string message = StringResources.TheConstructorOfTypeMustContainTheServiceTypeAsArgument( decoratorConstructor.DeclaringType, validConstructorArgumentTypes); throw new ArgumentException(message, paramName); }
private InstanceProducer BuildEmptyCollectionInstanceProducerForEnumerable(Type enumerableType) { Type elementType = enumerableType.GetGenericArguments()[0]; var collection = DecoratorHelpers.CreateContainerControlledCollection(elementType, this); var registration = new ExpressionRegistration(Expression.Constant(collection, enumerableType), this); // Producers for ExpressionRegistration are normally ignored as external producer, but in this // case the empty collection producer should pop up in the list of GetCurrentRegistrations(). return(new InstanceProducer(enumerableType, registration, registerExternalProducer: true)); }
protected override InstanceProducer BuildCollectionProducer(Type closedServiceType) { ContainerControlledItem[] closedGenericImplementations = this.GetClosedContainerControlledItemsFor(closedServiceType); IContainerControlledCollection collection = DecoratorHelpers.CreateContainerControlledCollection( closedServiceType, this.Container); collection.AppendAll(closedGenericImplementations); return(new InstanceProducer( typeof(IEnumerable <>).MakeGenericType(closedServiceType), DecoratorHelpers.CreateRegistrationForContainerControlledCollection(closedServiceType, collection, this.Container))); }
private Registration BuildContainerControlledRegistration(Type closedServiceType, Type[] closedGenericImplementations) { var registrations = ( from closedGenericImplementation in closedGenericImplementations select this.CreateRegistrationForClosedGenericImplementation( closedServiceType, closedGenericImplementation)) .ToArray(); IContainerControlledCollection collection = DecoratorHelpers.CreateContainerControlledCollection(closedServiceType, this.Container); collection.AppendAll(registrations); return(DecoratorHelpers.CreateRegistrationForContainerControlledCollection(closedServiceType, collection, this.Container)); }
private static void ThrowMustDecorateServiceType( Type serviceType, ConstructorInfo constructor, string paramName) { int numberOfServiceTypeDependencies = DecoratorHelpers.GetNumberOfServiceTypeDependencies(serviceType, constructor); if (numberOfServiceTypeDependencies == 0) { // We must get the real type to be decorated to prevent the exception message from being // confusing to the user. // At this point we know that the decorator type implements an service type in some way // (either open or closed), so we this call will return at least one record. serviceType = Types.GetBaseTypeCandidates(serviceType, constructor.DeclaringType).First(); ThrowMustContainTheServiceTypeAsArgument(serviceType, constructor, paramName); } else { ThrowMustContainASingleInstanceOfTheServiceTypeAsArgument(serviceType, constructor, paramName); } }
// TODO: Find out if the call to DecoratesBaseTypes is needed (all tests pass without it). internal static bool IsDecorator(Type serviceType, ConstructorInfo implementationConstructor) => DecoratorHelpers.DecoratesServiceType(serviceType, implementationConstructor) && DecoratorHelpers.DecoratesBaseTypes(serviceType, implementationConstructor);
private bool IsDecorator(Type serviceType, Type implementationType) { return(DecoratorHelpers.IsDecorator(this.container, serviceType, implementationType)); }
internal static bool IsDecorator(Type serviceType, ConstructorInfo implementationConstructor) { // TODO: Find out if the call to DecoratesBaseTypes is needed (all tests pass without it). return(DecoratorHelpers.DecoratesServiceType(serviceType, implementationConstructor) && DecoratorHelpers.DecoratesBaseTypes(serviceType, implementationConstructor)); }