Beispiel #1
0
            public bool CanSatisfy(DependencyCollection dependencies, PluginGraph graph)
            {
                foreach (var parameter in Parameters)
                {
                    var type = parameter.ParameterType;

                    if (type.IsGenericEnumerable())
                    {
                        // Because graph.HasFamily returns false for IEnumerable<T>,
                        // we unwrap the generic argument and pass that instead.
                        type = type.GenericTypeArguments[0];
                    }

                    if (graph.HasFamily(type))
                    {
                        continue;
                    }

                    if (dependencies.Any(dep => dep.Type == type))
                    {
                        continue;
                    }

                    return(false);
                }

                return(true);
            }
 // ASP.NET expects registered services to be considered when selecting a ctor, SM doesn't by default.
 public ConstructorInfo Find(Type pluggedType, DependencyCollection dependencies, PluginGraph graph) =>
 pluggedType.GetTypeInfo()
 .DeclaredConstructors
 .Where(ctor => ctor.IsConstructor && !ctor.IsPrivate)         // IsConstructor is false for static constructors
 .Select(ctor => new { Constructor = ctor, Parameters = ctor.GetParameters() })
 .Where(x => x.Parameters.All(param => graph.HasFamily(param.ParameterType) || dependencies.Any(dep => dep.Type == param.ParameterType)))
 .OrderByDescending(x => x.Parameters.Length)
 .Select(x => x.Constructor)
 .FirstOrDefault();