In the program you need to use extensions. I want to use the Managed Extensibility Framework for this. Since extensions must be created on demand and the extension may be required more than once, I want to get a list of the form

[ImportMany] SortedList<string, Type> extensions; 

And create instances yourself.


Now done so

Interfaces:

 public interface IStatement { void Process(); } public interface IStatementFactory { IEnumerable<string> Init(); IStatement CreateInstance(string declarer); } 

Loading:

 var catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(this.GetType().Assembly)); //Create the CompositionContainer with the parts in the catalog CompositionContainer _container = new CompositionContainer(catalog); try { _container.ComposeParts(this); } catch(CompositionException compositionException) { Console.WriteLine(compositionException.ToString()); } // [ImportMany(typeof(IStatementFactory))] // private IEnumerable<IStatementFactory> _factorys; _dict=new SortedDictionary<string, IStatementFactory>(); foreach(var f in _factorys) { foreach(string key in f.Init()) { _dict[key]=f; } } 

But I hope there is a better solution.

Thank.

    1 answer 1

    Well, you can shove the creation logic into a plugin. Let the facade return, hide the logic behind it.