public ConstructorOrderInfo(ConstructorInfo constructor, IReadOnlyDictionary <string, IConfigurationSection> availableMembers, IResolver resolver)
        {
            Constructor = constructor;
            var parameters = constructor.GetParameters();

            TotalParameters = parameters.Length;
            if (TotalParameters == 0)
            {
                IsInvokableWithoutDefaultParameters = true;
                IsInvokableWithDefaultParameters    = true;
                MissingParameterNames = Enumerable.Empty <string>();
                MatchedParameters     = 0;
            }
            else
            {
                bool HasAvailableValue(ParameterInfo p)
                {
                    return(p.GetNames().Any(availableMembers.ContainsKey) || resolver.CanResolve(p));
                }

                IsInvokableWithoutDefaultParameters = parameters.Count(HasAvailableValue) == TotalParameters;
                IsInvokableWithDefaultParameters    = parameters.Count(p => HasAvailableValue(p) || p.HasDefaultValue) == TotalParameters;
                MissingParameterNames = parameters.Where(p => !HasAvailableValue(p) && !p.HasDefaultValue).Select(p => p.Name);
                MatchedParameters     = parameters.Count(HasAvailableValue);
            }
        }
Exemplo n.º 2
0
 public bool CanResolve(ResolveContext context)
 {
     if (_instance != null)
     {
         return(true);
     }
     return(_innerResolver.CanResolve(context));
 }
Exemplo n.º 3
0
 public static bool CanResolve(this IResolver resolver, Type contractType, string identifier)
 {
     return(resolver.CanResolve(new InjectionContext
     {
         Container = resolver.Container,
         ContractType = contractType,
         Identifier = identifier
     }));
 }
Exemplo n.º 4
0
        protected virtual bool CanResolveParameter(ResolveContext context, ParameterInfo parameterInfo)
        {
            var       type     = parameterInfo.ParameterType;
            IResolver resolver = _locator.FindResolver(type);

            if (resolver == null)
            {
                return(false);
            }
            var childContext = new ResolveContext(context, type);

            return(resolver.CanResolve(childContext));
        }
Exemplo n.º 5
0
 public object Get(InjectionContext context)
 {
     if (resolver.CanResolve(context))
     {
         return(resolver.Resolve(context));
     }
     else if (parent != null && parent.Resolver.CanResolve(context))
     {
         return(parent.Resolver.Resolve(context));
     }
     else if (instantiator.CanInstantiate(context))
     {
         return(instantiator.Instantiate(context));
     }
     else if (parent != null && parent.Instantiator.CanInstantiate(context))
     {
         return(parent.Instantiator.Instantiate(context));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 6
0
 public static bool CanGet(this IResolver resolver, Type type, IConstraint constraint)
 {
     return(resolver.CanResolve(type, constraint));
 }
Exemplo n.º 7
0
 public static bool CanGet(this IResolver resolver, Type type, string name)
 {
     return(resolver.CanResolve(type, new NameConstraint(name)));
 }
Exemplo n.º 8
0
 public static bool CanGet(this IResolver resolver, Type type)
 {
     return(resolver.CanResolve(type, null));
 }
Exemplo n.º 9
0
 public static bool CanGet <T>(this IResolver resolver, IConstraint constraint)
 {
     return(resolver.CanResolve(typeof(T), constraint));
 }
Exemplo n.º 10
0
 public static bool CanGet <T>(this IResolver resolver, string name)
 {
     return(resolver.CanResolve(typeof(T), new NameConstraint(name)));
 }
Exemplo n.º 11
0
 public static bool CanGet <T>(this IResolver resolver)
 {
     return(resolver.CanResolve(typeof(T), null));
 }
Exemplo n.º 12
0
 public static bool CanResolve <TContract>(this IResolver resolver, string identifier)
 {
     return(resolver.CanResolve(typeof(TContract), identifier));
 }
Exemplo n.º 13
0
 public static bool CanResolve <TContract>(this IResolver resolver)
 {
     return(resolver.CanResolve(typeof(TContract)));
 }
Exemplo n.º 14
0
 public static bool CanResolve(this IResolver resolver, Type contractType)
 {
     return(resolver.CanResolve(contractType, ""));
 }