MEF - I need to implement IPartImportsSatisfiedNotification

public interface IPlugin
{
    public bool execute();
}

All my "parts" implement this IPlugin interface. My parts clearly have import / export requirements / suggestions.

I am writing a build system + config in which the user dynamically selects what he / she wants, which translates to the called set of plug-ins.

For example, here is a list of plugins:

(1) Install X ... export "XTypeInstalled"

(2) Configure X ... imports "XTypeInstalled", exports "XTypeConfigured"

(3) Set Y ... imports "XTypeConfigured"

(4) Set Z

(5) Configure A

Now the user can select (1), (3) and (4) ... or select (1), (2), (3)

, , IPartImportsSatisfiedNotification? , (1), (2) (3)... (3) execute().

?!

+3
1

MEF , . MEF - , , .

, , , .

, , , .

, MEF , , MEF .

:.

[Export(typeof(IPlugin)), ExportMetadata("Name", "ConfigureX")]
public class ConfigureXPlugin : IPlugin { ...

MEF, :

public class BuildRunner {
  [ImportMany]
  Lazy<IPlugin, IPluginMetadata> plugins[];

  void RunBuild(...) {
    // Figure out which tasks should execute, in which order, and call each of them

, . - , ​​ .

+4

Source: https://habr.com/ru/post/1716457/


All Articles