示例#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);
 }
 public ConditionalPluginsDsl(
     ConditionalPlugins <TPlugin, TContext> plugins,
     Func <TContext, bool> defaultPredicate = null)
 {
     Plugins          = plugins;
     DefaultPredicate = defaultPredicate;
 }
示例#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);
 }
示例#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)));
 }
示例#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()));
 }
示例#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)));
 }
 public ReplaceDsl(ConditionalPluginsDsl <TPlugin, TContext> dsl,
                   ConditionalPlugins <TPlugin, TContext> plugins,
                   Func <TContext, bool> defaultPredicate)
 {
     _dsl              = dsl;
     _plugins          = plugins;
     _defaultPredicate = defaultPredicate;
 }
示例#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());
 }
示例#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());
 }
 public PrependDsl(ConditionalPlugin <TPlugin, TContext> plugin,
                   ConditionalPlugins <TPlugin, TContext> plugins,
                   Func <TContext, bool> defaultPredicate) : base(plugins, defaultPredicate)
 {
     _plugin = plugin;
 }