Ejemplo n.º 1
0
        public static PluginDefinitions <TPlugin, TContext> Create(
            Action <PluginDefinitions <TPlugin, TContext> > config = null)
        {
            var plugins = new PluginDefinitions <TPlugin, TContext>();

            config?.Invoke(plugins);
            return(plugins);
        }
Ejemplo n.º 2
0
 public static IEnumerable <TPlugin> ThatApplyTo <TPlugin, TContext>(
     this PluginDefinitions <TPlugin, TContext> definitions,
     IEnumerable <TPlugin> plugins, TContext context)
     where TPlugin : IConditional <TContext>
 {
     return(plugins
            .Where(x => x != null)
            .GroupJoin(definitions, d => d.GetType(), p => p.Type, (p, d) => new
     {
         Instance = p,
         Order = definitions.Order(p),
         d.FirstOrDefault()?.AppliesTo
     })
            .Where(x => (x.AppliesTo?.Invoke(context) ?? true) && x.Instance.AppliesTo(context))
            .OrderBy(x => x.Order)
            .Select(x => x.Instance).ToList());
 }
Ejemplo n.º 3
0
 public ReplaceDsl(PluginDefinitions <TPlugin, TContext> plugins)
 {
     _plugins = plugins;
 }
Ejemplo n.º 4
0
 public static void RegisterPlugins <TPlugin, TContext>(this IContainer container,
                                                        PluginDefinitions <TPlugin, TContext> pluginDefinitions)
     where TPlugin : class, IConditional <TContext>
 {
     pluginDefinitions.ForEach(pd => container.Register <TPlugin>(pd.Type, pd.Singleton));
 }