Пример #1
0
        /// <summary>
        /// Try to find a constructor by looking at the most specific first.
        /// </summary>
        /// <param name="concreteType">Type to create</param>
        /// <param name="constructor">Chosen constructor</param>
        /// <returns>Error if any; otherwise null.</returns>
        protected virtual FailureReasons TryGetConstructor(Type concreteType, out ConstructorInfo constructor)
        {
            var error = new FailureReasons(concreteType);

            foreach (var constructorInfo in concreteType.GetConstructors().OrderByDescending(x => x.GetParameters().Length))
            {
                var missing = FindMissingArgument(constructorInfo);
                if (missing == null)
                {
                    constructor = constructorInfo;
                    return(null);
                }

                error.Add(new ConstructorFailedReason(constructorInfo, missing.ParameterType));
            }

            constructor = null;
            return(error);
        }
Пример #2
0
        /// <summary>
        /// Try to find a constructor by looking at the most specific first.
        /// </summary>
        /// <param name="concreteType">Type to create</param>
        /// <param name="constructor">Chosen constructor</param>
        /// <returns>Error if any; otherwise null.</returns>
        protected virtual FailureReasons TryGetConstructor(Type concreteType, out ConstructorInfo constructor)
        {
            var error = new FailureReasons(concreteType);
            foreach (var constructorInfo in concreteType.GetConstructors().OrderByDescending(x => x.GetParameters().Length))
            {
                var missing =
                    constructorInfo.GetParameters().FirstOrDefault(
                        parameter => !_registrar.Registrations.Any(x => x.Implements(parameter.ParameterType)));

                if (missing == null)
                {
                    constructor = constructorInfo;
                    return null;
                }


                error.Add(new ConstructorFailedReason(constructorInfo, missing.ParameterType));
            }

            constructor = null;
            return error;
        }
        /// <summary>
        /// Try to find a constructor by looking at the most specific first.
        /// </summary>
        /// <param name="concreteType">Type to create</param>
        /// <param name="constructor">Chosen constructor</param>
        /// <returns>Error if any; otherwise null.</returns>
        protected virtual FailureReasons TryGetConstructor(Type concreteType, out ConstructorInfo constructor)
        {
            var error = new FailureReasons(concreteType);
            foreach (var constructorInfo in concreteType.GetConstructors().OrderByDescending(x => x.GetParameters().Length))
            {
                var missing = FindMissingArgument(constructorInfo);
                if (missing == null)
                {
                    constructor = constructorInfo;
                    return null;
                }

                error.Add(new ConstructorFailedReason(constructorInfo, missing.ParameterType));
            }

            constructor = null;
            return error;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConcreteDependencyMissingException"/> class.
 /// </summary>
 /// <param name="concreteType">Type of the concrete which could not be built.</param>
 /// <param name="error">The error.</param>
 public ConcreteDependencyMissingException(Type concreteType, FailureReasons error)
     : base(string.Format("Failed to lookup '{0}'.", concreteType.FullName))
 {
     ConcreteBeingBuilt = concreteType;
     Reasons = error;
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConcreteDependencyMissingException"/> class.
 /// </summary>
 /// <param name="concreteType">Type of the concrete which could not be built.</param>
 /// <param name="error">The error.</param>
 public ConcreteDependencyMissingException(Type concreteType, FailureReasons error)
     : base(string.Format("Failed to create '{0}'.", concreteType.FullName))
 {
     ConcreteBeingBuilt = concreteType;
     Reasons            = error;
 }