public static IEnumerable <ZenjectResolveException> ValidateContract(
            DiContainer container, Type contractType, ResolveContext context, bool isOptional)
        {
            var matches = container.GetProviderMatches(contractType, context);

            if (matches.IsLength(1))
            {
                foreach (var error in matches.Single().ValidateBinding())
                {
                    yield return(error);
                }
            }
            else
            {
                if (ReflectionUtil.IsGenericList(contractType))
                {
                    var subType = contractType.GetGenericArguments().Single();

                    matches = container.GetProviderMatches(subType, context);

                    if (matches.IsEmpty())
                    {
                        if (!isOptional)
                        {
                            yield return(new ZenjectResolveException(
                                             "Could not find dependency with type 'List<{0}>' when injecting into '{1}.  If the empty list is also valid, you can allow this by using the [InjectOptional] attribute.' \nObject graph:\n{2}"
                                             .With(subType.Name(), context.EnclosingType.Name(), container.GetCurrentObjectGraph())));
                        }
                    }
                    else
                    {
                        foreach (var match in matches)
                        {
                            foreach (var error in match.ValidateBinding())
                            {
                                yield return(error);
                            }
                        }
                    }
                }
                else
                {
                    if (!isOptional)
                    {
                        if (matches.IsEmpty())
                        {
                            yield return(new ZenjectResolveException(
                                             "Could not find required dependency with type '{0}' when injecting into '{1}' \nObject graph:\n{2}"
                                             .With(contractType.Name(), context.EnclosingType.Name(), container.GetCurrentObjectGraph())));
                        }
                        else
                        {
                            yield return(new ZenjectResolveException(
                                             "Found multiple matches when only one was expected for dependency with type '{0}' when injecting into '{1}' \nObject graph:\n{2}"
                                             .With(contractType.Name(), context.EnclosingType.Name(), container.GetCurrentObjectGraph())));
                        }
                    }
                }
            }
        }