Exemplo n.º 1
0
        public TypePluginProviders(Type pluginType, Action <PluginNameOptions> configure, PluginNameOptions nameOptions, TypePluginOptions options)
        {
            if (pluginType == null)
            {
                throw new ArgumentNullException(nameof(pluginType));
            }

            _pluginType = pluginType;
            _options    = options ?? new TypePluginOptions();

            if (_options.TypeFinderCriterias == null)
            {
                _options.TypeFinderCriterias = new Dictionary <string, TypeFinderCriteria>();
            }

            if (_options.TypeFinderCriterias.Any() != true)
            {
                _options.TypeFinderCriterias.Add(string.Empty, new TypeFinderCriteria()
                {
                    Query = (context, type) => true
                });
            }

            if (_options.TypeFindingContext == null)
            {
                _options.TypeFindingContext = new PluginAssemblyLoadContext(pluginType.Assembly);
            }

            if (_options.TypeFinderOptions == null)
            {
                _options.TypeFinderOptions = new TypeFinderOptions();
            }

            if (_options.TypeFinderOptions.TypeFinderCriterias?.Any() != true)
            {
                _options.TypeFinderOptions.TypeFinderCriterias = new List <TypeFinderCriteria>();

                if (_options.TypeFinderCriterias?.Any() == true)
                {
                    foreach (var typeFinderCriteria in _options.TypeFinderCriterias)
                    {
                        var typeFinder = typeFinderCriteria.Value;
                        typeFinder.Tags = new List <string>()
                        {
                            typeFinderCriteria.Key
                        };

                        _options.TypeFinderOptions.TypeFinderCriterias.Add(typeFinder);
                    }
                }
            }

            if (configure == null && nameOptions == null)
            {
                return;
            }

            var naming = nameOptions ?? new PluginNameOptions();

            configure?.Invoke(naming);

            _options.PluginNameOptions = naming;
        }
Exemplo n.º 2
0
 public TypePluginProviders(Type pluginType, TypePluginOptions options) : this(pluginType, null, null, options)
 {
 }