Ejemplo n.º 1
0
 public static Registry RegisterPlugins <TPlugin, TContext>(this Registry registry,
                                                            ConditionalPlugins <TPlugin, TContext> plugins)
     where TPlugin : class
 {
     plugins.ForEach(x => registry.RegisterPlugin(x));
     return(registry);
 }
Ejemplo n.º 2
0
 public ConditionalPluginsDsl(
     ConditionalPlugins <TPlugin, TContext> plugins,
     Func <TContext, bool> defaultPredicate = null)
 {
     Plugins          = plugins;
     DefaultPredicate = defaultPredicate;
 }
Ejemplo n.º 3
0
 public static IContainer RegisterPlugins <TPlugin, TContext>(this IContainer container,
                                                              ConditionalPlugins <TPlugin, TContext> plugins)
     where TPlugin : class
 {
     plugins.ForEach(x => container.RegisterPlugin(x));
     return(container);
 }
Ejemplo n.º 4
0
 public static IEnumerable <TPlugin> ThatAppliesTo <TPlugin, TPluginContext, TInstanceContext>(
     this ConditionalPlugins <TPlugin, TPluginContext> plugins,
     IEnumerable <TPlugin> instances, TPluginContext pluginContext, TInstanceContext instanceContext)
     where TPlugin : IConditional <TInstanceContext>
 {
     return(plugins.ThatApply(instances, pluginContext, x => x.AppliesTo(instanceContext)));
 }
Ejemplo n.º 5
0
 public static IEnumerable <TPlugin> ThatAppliesOrDefault <TPlugin, TPluginContext>(
     this ConditionalPlugins <TPlugin, TPluginContext> plugins,
     IEnumerable <TPlugin> instances, TPluginContext pluginContext)
     where TPlugin : class, IConditional
 {
     return(plugins.ThatApplyOrDefault(instances, pluginContext, x => x.Applies()));
 }
Ejemplo n.º 6
0
 private static IEnumerable <TPlugin> ThatApplyOrDefault <TPlugin, TPluginContext>(
     this ConditionalPlugins <TPlugin, TPluginContext> plugins,
     IEnumerable <TPlugin> instances, TPluginContext pluginContext, Func <TPlugin, bool> predicate)
 {
     return(plugins.ThatApply(instances, pluginContext, predicate).ToList()
            .AnyOrDefault(() => plugins.GetDefaultInstance(instances)));
 }
Ejemplo n.º 7
0
 public ReplaceDsl(ConditionalPluginsDsl <TPlugin, TContext> dsl,
                   ConditionalPlugins <TPlugin, TContext> plugins,
                   Func <TContext, bool> defaultPredicate)
 {
     _dsl              = dsl;
     _plugins          = plugins;
     _defaultPredicate = defaultPredicate;
 }
Ejemplo n.º 8
0
 private static IEnumerable <TPlugin> ThatApply <TPlugin, TPluginContext>(
     this ConditionalPlugins <TPlugin, TPluginContext> plugins,
     IEnumerable <TPlugin> instances, TPluginContext pluginContext, Func <TPlugin, bool> predicate)
 {
     return(plugins.ThatApplyTo(instances, pluginContext)
            .Where(x => predicate.Invoke(x.Instance))
            .Select(x => x.Instance).ToList());
 }
Ejemplo n.º 9
0
 public static TPlugin FirstThatAppliesToOrDefault <TPlugin, TPluginContext, TInstanceContext>(
     this ConditionalPlugins <TPlugin, TPluginContext> plugins,
     IEnumerable <TPlugin> instances, TPluginContext pluginContext,
     TInstanceContext instanceContext)
     where TPlugin : class, IConditional <TInstanceContext>
 {
     return(plugins.ThatAppliesToOrDefault(instances,
                                           pluginContext, instanceContext).FirstOrDefault());
 }
Ejemplo n.º 10
0
 public PrependDsl(ConditionalPlugin <TPlugin, TContext> plugin,
                   ConditionalPlugins <TPlugin, TContext> plugins,
                   Func <TContext, bool> defaultPredicate) : base(plugins, defaultPredicate)
 {
     _plugin = plugin;
 }