internal static string NoRegistrationForTypeFound(Type serviceType, bool containerHasRegistrations)
 {
     return string.Format(CultureInfo.InvariantCulture,
         "No registration for type {0} could be found.{1}", 
         serviceType.ToFriendlyName(),
         ContainsHasNoRegistrationsAddition(containerHasRegistrations));
 }
Esempio n. 2
0
        // This method takes generic type and returns a 'partially' generic type definition of that same type,
        // where all generic arguments up to the given nesting level. This allows us to group generic types
        // by their partial generic type definition, which allows a much nicer user experience.
        internal static Type MakeTypePartiallyGenericUpToLevel(Type type, int nestingLevel)
        {
            if (nestingLevel > 100)
            {
                // Stack overflow prevention
                throw new ArgumentException("nesting level bigger than 100 too high. Type: " +
                    type.ToFriendlyName(), nameof(nestingLevel));
            }

            // example given type: IEnumerable<IQueryProcessor<MyQuery<Alpha>, int[]>>
            // nestingLevel 4 returns: IEnumerable<IQueryHandler<MyQuery<Alpha>, int[]>
            // nestingLevel 3 returns: IEnumerable<IQueryHandler<MyQuery<Alpha>, int[]>
            // nestingLevel 2 returns: IEnumerable<IQueryHandler<MyQuery<T>, int[]>
            // nestingLevel 1 returns: IEnumerable<IQueryHandler<TQuery, TResult>>
            // nestingLevel 0 returns: IEnumerable<T>
            if (!type.IsGenericType)
            {
                return type;
            }

            if (nestingLevel == 0)
            {
                return type.GetGenericTypeDefinition();
            }

            return MakeTypePartiallyGeneric(type, nestingLevel);
        }
 internal static string ErrorWhileBuildingDelegateFromExpression(Type serviceType,
     Expression expression, Exception exception)
 {
     return string.Format(CultureInfo.InvariantCulture,
         "Error occurred while trying to build a delegate for type {0} using the expression \"{1}\". " +
         "{2}", serviceType.ToFriendlyName(), expression, exception.Message);
 }
 private static DebuggerViewItem[] GetDebugValue(Type implementationType, InstanceProducer[] dependencies)
 {
     return new[]
     {
         new DebuggerViewItem("ImplementationType", implementationType.ToFriendlyName(), implementationType),
         new DebuggerViewItem("Dependencies", dependencies.Length + " dependencies.", dependencies),
     };
 }
Esempio n. 5
0
 internal static string NoRegistrationForTypeFound(Type serviceType, bool containerHasRegistrations,
     bool containerHasRelatedOneToOneMapping, bool containerHasRelatedCollectionMapping,
     Type[] skippedDecorators) => 
     string.Format(CultureInfo.InvariantCulture,
         "No registration for type {0} could be found.{1}{2}{3}{4}",
         serviceType.ToFriendlyName(),
         ContainerHasNoRegistrationsAddition(containerHasRegistrations),
         DidYouMeanToCallGetInstanceInstead(containerHasRelatedOneToOneMapping, serviceType),
         DidYouMeanToCallGetAllInstancesInstead(containerHasRelatedCollectionMapping, serviceType),
         NoteThatSkippedDecoratorsWereFound(serviceType, skippedDecorators));
Esempio n. 6
0
        static string CreateMessage(Type messageType, IEnumerable<Exception> exceptions)
        {
            SendException sendException = exceptions
                .Where(x => x.GetType() == typeof(SendException))
                .Cast<SendException>()
                .FirstOrDefault();

            if (sendException != null)
            {
                return string.Format("At least one exception occurred publishing {0} to {1}",
                    sendException.MessageType.ToFriendlyName(), sendException.Uri);
            }

            return string.Format("At least one exception occurred publishing {0}",
                messageType.ToFriendlyName());
        }
 private static DebuggerViewItem[] CreateDebugValue(Type implementationType, Lifestyle lifestyle,
     InstanceProducer[] affectedRegistrations)
 {
     return new[]
     {
         new DebuggerViewItem(
             name: "ImplementationType", 
             description: implementationType.ToFriendlyName(), 
             value: implementationType),
         new DebuggerViewItem(
             name: "Lifestyle", 
             description: lifestyle.Name, 
             value: lifestyle),
         new DebuggerViewItem(
             name: "Affected Registrations", 
             description: ToCommaSeparatedText(affectedRegistrations), 
             value: affectedRegistrations)
     };
 }
 private static DebuggerViewItem[] CreateDebugValue(Type implementationType, Lifestyle[] lifestyles,
     InstanceProducer[] conflictingRegistrations)
 {
     return new[]
     {
         new DebuggerViewItem(
             name: "ImplementationType", 
             description: implementationType.ToFriendlyName(), 
             value: implementationType),
         new DebuggerViewItem(
             name: "Lifestyles", 
             description: ToCommaSeparatedText(lifestyles), 
             value: lifestyles),
         new DebuggerViewItem(
             name: "Conflicting Registrations", 
             description: ToCommaSeparatedText(conflictingRegistrations), 
             value: conflictingRegistrations)
     };
 }
Esempio n. 9
0
 private static string DidYouMeanToCallGetAllInstancesInstead(bool hasCollection, Type serviceType) =>
     hasCollection
         ? string.Format(CultureInfo.InvariantCulture,
             " There is, however, a registration for {0}; Did you mean to call " +
             "GetAllInstances<{1}>() or depend on {0}?",
             typeof(IEnumerable<>).MakeGenericType(serviceType).ToFriendlyName(),
             serviceType.ToFriendlyName())
         : string.Empty;
Esempio n. 10
0
 internal static string DelegateForTypeThrewAnException(Type serviceType) => 
     string.Format(CultureInfo.InvariantCulture,
         "The registered delegate for type {0} threw an exception.", serviceType.ToFriendlyName());
Esempio n. 11
0
        internal static string AnOverlappingRegistrationExists(Type openGenericServiceType,
            Type overlappingImplementationType, bool isExistingRegistrationConditional,
            Type implementationTypeOfNewRegistration, bool isNewRegistrationConditional)
        {
            string solution = "Either remove one of the registrations or make them both conditional.";

            if (isExistingRegistrationConditional && isNewRegistrationConditional &&
                overlappingImplementationType == implementationTypeOfNewRegistration)
            {
                solution =
                    "You can merge both registrations into a single conditional registration and combine " +
                    "both predicates into one single predicate.";
            }

            return string.Format(CultureInfo.InvariantCulture,
                "There is already a {0}registration for {1} (with implementation {2}) that " +
                "overlaps with the registration for {3} that you are trying to make. This new " +
                "registration would cause ambiguity, because both registrations would be used for the " +
                "same closed service types. {4}",
                isExistingRegistrationConditional ? "conditional " : string.Empty,
                openGenericServiceType.ToFriendlyName(),
                overlappingImplementationType.ToFriendlyName(),
                implementationTypeOfNewRegistration.ToFriendlyName(),
                solution);
        }
Esempio n. 12
0
 internal static string ServiceTypeCannotBeAPartiallyClosedType(Type openGenericServiceType,
     string serviceTypeParamName, string implementationTypeParamName) => 
     string.Format(CultureInfo.InvariantCulture,
         "The supplied type '{0}' is a partially-closed generic type, which is not supported as " +
         "value of the {1} parameter. Instead, please supply the open generic type '{2}' and make " +
         "the type supplied to the {3} parameter partially-closed instead.",
         openGenericServiceType.ToFriendlyName(),
         serviceTypeParamName,
         Helpers.ToCSharpFriendlyName(openGenericServiceType.GetGenericTypeDefinition()),
         implementationTypeParamName);
Esempio n. 13
0
 internal static string TypeFactoryReturnedIncompatibleType(Type serviceType, Type implementationType) =>
     string.Format(CultureInfo.InvariantCulture,
         "The registered type factory returned type {0} which does not implement {1}.",
         implementationType.ToFriendlyName(), serviceType.ToFriendlyName());
Esempio n. 14
0
 internal static string OpenGenericTypeContainsUnresolvableTypeArguments(Type openGenericImplementation) => 
     string.Format(CultureInfo.InvariantCulture,
         "The supplied type {0} contains unresolvable type arguments. " +
         "The type would never be resolved and is therefore not suited to be used.",
         openGenericImplementation.ToFriendlyName());
Esempio n. 15
0
 internal static string TheConstructorOfTypeMustContainASingleInstanceOfTheServiceTypeAsArgument(
     Type decoratorType, Type serviceType) => 
     string.Format(CultureInfo.InvariantCulture,
         "For the container to be able to use {0} as a decorator, its constructor must include a " +
         "single parameter of type {1} (or Func<{1}>) - i.e. the type of the instance that is being " +
         "decorated. The parameter type {1} is defined multiple times in the constructor of class {0}.",
         decoratorType.ToFriendlyName(), serviceType.ToFriendlyName());
Esempio n. 16
0
 internal static string ImplementationTypeFactoryReturnedNull(Type serviceType) => 
     string.Format(CultureInfo.InvariantCulture,
         "The implementation type factory delegate that was registered for service type {0} returned null.",
         serviceType.ToFriendlyName());
Esempio n. 17
0
 internal static string TheTypeReturnedFromTheFactoryShouldNotBeOpenGeneric(
     Type serviceType, Type implementationType) =>
     string.Format(CultureInfo.InvariantCulture,
         "The registered type factory returned open generic type {0} while the registered service " +
         "type {1} is not generic, making it impossible for a closed generic type to be constructed.",
         implementationType.ToFriendlyName(),
         serviceType.ToFriendlyName());
Esempio n. 18
0
 internal static string DecoratorCanNotBeAGenericTypeDefinitionWhenServiceTypeIsNot(Type serviceType,
     Type decoratorType) => 
     string.Format(CultureInfo.InvariantCulture,
         "The supplied decorator {0} is an open generic type definition, while the supplied " +
         "service type {1} is not.", decoratorType.ToFriendlyName(), serviceType.ToFriendlyName());
Esempio n. 19
0
 internal static string ServiceTypeCannotBeAPartiallyClosedType(Type openGenericServiceType) => 
     string.Format(CultureInfo.InvariantCulture,
         "The supplied type '{0}' is a partially-closed generic type, which is not supported by " +
         "this method. Please supply the open generic type '{1}' instead.",
         openGenericServiceType.ToFriendlyName(),
         Helpers.ToCSharpFriendlyName(openGenericServiceType.GetGenericTypeDefinition()));
Esempio n. 20
0
 internal static string CanNotDecorateContainerUncontrolledCollectionWithThisLifestyle(
     Type decoratorType, Lifestyle lifestyle, Type serviceType) => 
     string.Format(CultureInfo.InvariantCulture,
         "You are trying to apply the {0} decorator with the '{1}' lifestyle to a collection of " +
         "type {2}, but the registered collection is not controlled by the container. Since the " +
         "number of returned items might change on each call, the decorator with this lifestyle " +
         "cannot be applied to the collection. Instead, register the decorator with the Transient " +
         "lifestyle, or use one of the {3} overloads that takes a collection of System.Type types.",
         decoratorType.ToFriendlyName(), 
         lifestyle.Name, 
         serviceType.ToFriendlyName(),
         nameof(Container.RegisterCollection));
Esempio n. 21
0
 internal static string RegistrationForClosedServiceTypeOverlapsWithOpenGenericRegistration(
     Type closedServiceType, Type overlappingGenericImplementationType) =>
     string.Format(CultureInfo.InvariantCulture,
         "There is already an open generic registration for {0} (with implementation {1}) that " +
         "overlaps with the registration of {2} that you are trying to make. If your intention is " +
         "to use {1} as fallback registration, please instead call: " +
         "{5}(typeof({3}), typeof({4}), c => !c.Handled).",
         closedServiceType.GetGenericTypeDefinition().ToFriendlyName(),
         overlappingGenericImplementationType.ToFriendlyName(),
         closedServiceType.ToFriendlyName(),
         Helpers.ToCSharpFriendlyName(closedServiceType.GetGenericTypeDefinition()),
         Helpers.ToCSharpFriendlyName(overlappingGenericImplementationType),
         nameof(Container.RegisterConditional));
Esempio n. 22
0
 internal static string AppendingRegistrationsToContainerUncontrolledCollectionsIsNotSupported(
     Type serviceType) => 
     string.Format(CultureInfo.InvariantCulture,
         "You are trying to append a registration to the registered collection of {0} instances, " +
         "which is either registered using {1}<TService>(IEnumerable<TService>) or " +
         "{1}(Type, IEnumerable). Since the number of returned items might change on each call, " +
         "appending registrations to these collections is not supported. Please register the " +
         "collection with one of the other {1} overloads if appending is required.",
         serviceType.ToFriendlyName(),
         nameof(Container.RegisterCollection));
Esempio n. 23
0
 internal static string MultipleApplicableRegistrationsFound(Type serviceType,
     Tuple<Type, Type, InstanceProducer>[] overlappingRegistrations) => 
     string.Format(CultureInfo.InvariantCulture,
         "Multiple applicable registrations found for {0}. The applicable registrations are {1}. " +
         "If your goal is to make one registration a fallback in case another registration is not " +
         "applicable, make the fallback registration last using RegisterConditional and make sure " +
         "the supplied predicate returns false in case the Handled property is true.",
         serviceType.ToFriendlyName(),
         overlappingRegistrations.Select(BuildRegistrationName).ToCommaSeparatedText());
Esempio n. 24
0
 internal static string UnregisteredTypeEventArgsRegisterDelegateReturnedUncastableInstance(
     Type serviceType, InvalidCastException exception) => 
     string.Format(CultureInfo.InvariantCulture,
         "The delegate that was registered for service type {0} using the {2}.{3}(Func<object>) " +
         "method returned an object that couldn't be casted to {0}. {1}",
         serviceType.ToFriendlyName(), 
         exception.Message,
         nameof(UnregisteredTypeEventArgs),
         nameof(UnregisteredTypeEventArgs.Register));
Esempio n. 25
0
 private static string NonGenericTypeAlreadyRegistered(Type serviceType,
     bool existingRegistrationIsConditional)
 {
     return string.Format(CultureInfo.InvariantCulture,
         "Type {0} has already been registered as {1} registration. For non-generic types, " +
         "conditional and unconditional registrations can't be mixed.",
         serviceType.ToFriendlyName(),
         existingRegistrationIsConditional ? "conditional" : "unconditional");
 }
Esempio n. 26
0
 internal static string UnregisteredTypeEventArgsRegisterDelegateThrewAnException(Type serviceType,
     Exception exception) => 
     string.Format(CultureInfo.InvariantCulture,
         "The delegate that was registered for service type {0} using the {2}.{3}(Func<object>) " + 
         "method threw an exception. {1}",
         serviceType.ToFriendlyName(), 
         exception.Message,
         nameof(UnregisteredTypeEventArgs),
         nameof(UnregisteredTypeEventArgs.Register));
Esempio n. 27
0
 private static string SuppliedTypeIsNotGenericExplainingAlternatives(Type type, string registeringElement) => 
     string.Format(CultureInfo.InvariantCulture,
         "This method only supports open generic types. " +
         "If you meant to register all available implementations of {0}, call " +
         "{2}(typeof({0}), IEnumerable<{1}>) instead.",
         type.ToFriendlyName(),
         registeringElement,
         nameof(Container.RegisterCollection));
Esempio n. 28
0
 internal static string TheServiceIsRequestedOutsideTheContextOfAScopedLifestyle(Type serviceType,
     ScopedLifestyle lifestyle) => 
     string.Format(CultureInfo.InvariantCulture,
         "The {0} is registered as '{1}' lifestyle, but the instance is requested outside the " +
         "context of a {1}.",
         serviceType.ToFriendlyName(),
         lifestyle.Name);
Esempio n. 29
0
 internal static string OpenGenericTypesCanNotBeResolved(Type serviceType) => 
     string.Format(CultureInfo.InvariantCulture,
         "The request for type {0} is invalid because it is an open generic type: it is only " +
         "possible to instantiate instances of closed generic types. A generic type is closed if " +
         "all of its type parameters have been substituted with types that are recognized by the " +
         "compiler.",
         serviceType.ToFriendlyName());
Esempio n. 30
0
 internal static string DelegateForTypeReturnedNull(Type serviceType) => 
     string.Format(CultureInfo.InvariantCulture,
         "The registered delegate for type {0} returned null.", serviceType.ToFriendlyName());