private static void ThrowIfMarkerInterfaceIsRegistered(PluginGraph graph) { if (graph.HasFamily <IMarkerInterface>()) { throw new InvalidOperationException("Populate should only be called once per container."); } }
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 .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();
public ConstructorInfo Find(Type pluggedType, DependencyCollection dependencies, PluginGraph graph) { return(pluggedType.GetTypeInfo() .DeclaredConstructors .Select(ctor => Tuple.Create(ctor, ctor.GetParameters())) .Where(tuple => tuple.Item2.All(param => graph.HasFamily(param.ParameterType))) .OrderByDescending(tuple => tuple.Item2.Length) .Select(tuple => tuple.Item1) .FirstOrDefault()); }
public ILifecycle DefaultLifecycleFor(Type pluginType) { if (pluginType == null) { return(null); } if (!_pluginGraph.HasFamily(pluginType)) { return(null); } return(_pluginGraph.Families[pluginType].Lifecycle); }
public static bool HasFamily <TPlugin>(this PluginGraph graph) { return(graph.HasFamily(typeof(TPlugin))); }