private ConstructorInfo SelectConstructor( Type typeToConstruct, RegistrationContext registrationContext, ResolutionContext resolutionContext, IEnumerable <ConstructorInfo> constructorsEnumerable, out Expression[] parameterExpressions) { ConstructorInfo[] constructors = null; if (resolutionContext.ParameterExpressions.Length > 0) { var containingFactoryParameter = constructorsEnumerable .Where(c => c.GetParameters() .Any(p => resolutionContext.ParameterExpressions .WhereOrDefault(pe => pe.Any(pexp => pexp.I2.Type == p.ParameterType || pexp.I2.Type.Implements(p.ParameterType)))?.Any() ?? false)); var everythingElse = constructorsEnumerable.Except(containingFactoryParameter); constructors = containingFactoryParameter.Concat(everythingElse).CastToArray(); } else { constructors = constructorsEnumerable.CastToArray(); } if (constructors.Length == 0) { throw new ResolutionFailedException(typeToConstruct, registrationContext.Name, "No public constructor found. Make sure there is at least one public constructor on the type."); } var checkedConstructors = new Dictionary <MethodBase, TypeInformation>(); var unknownTypeCheckDisabledContext = resolutionContext.CurrentContainerContext.ContainerConfiguration.UnknownTypeResolutionEnabled ? resolutionContext.BeginUnknownTypeCheckDisabledContext() : resolutionContext; var length = constructors.Length; for (var i = 0; i < length; i++) { var constructor = constructors[i]; if (TryBuildMethod(constructor, registrationContext, unknownTypeCheckDisabledContext, out var failedParameter, out parameterExpressions)) { return(constructor); } checkedConstructors.Add(constructor, failedParameter); } if (resolutionContext.CurrentContainerContext.ContainerConfiguration.UnknownTypeResolutionEnabled) { for (var i = 0; i < length; i++) { var constructor = constructors[i]; if (TryBuildMethod(constructor, registrationContext, resolutionContext, out _, out parameterExpressions)) { return(constructor); } } } if (resolutionContext.NullResultAllowed) { parameterExpressions = null; return(null); } var stringBuilder = new StringBuilder(); foreach (var checkedConstructor in checkedConstructors) { stringBuilder.AppendLine($"Constructor {checkedConstructor.Key} found with unresolvable parameter: ({checkedConstructor.Value.Type.FullName}){checkedConstructor.Value.ParameterOrMemberName}."); } throw new ResolutionFailedException(typeToConstruct, registrationContext.Name, stringBuilder.ToString()); }