Esempio n. 1
0
        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 = Helpers.GetBaseTypeCandidates(serviceType, constructor.DeclaringType).First();

                ThrowMustContainTheServiceTypeAsArgument(serviceType, constructor, paramName);
            }
            else
            {
                ThrowMustContainASingleInstanceOfTheServiceTypeAsArgument(serviceType, constructor, paramName);
            }
        }