lacop
lacop

Reputation: 2044

Extensible WPF application - MEF, MAF or simple loading?

(I know about the other MEF/MAF questions but this is a more specific problem)

I want to create a WPF application that will basically be just a simple add-in host, GUI and settings. All of the actual work will be done by one or more plugin(s). They don't need to communicate between each other, the main application will send user input/commands to them and they will return some results (for example, WPF UI elements to render).

Now, since the core of the application will be based on plugins I need to pick a good way to manage them. I want to be able to load/unload/reload them at runtime (for example when an update is found and downloaded). They should probably run in own application domain and/or process for stability and safety.

From some research and experiments I came to three options:

So, which one would be best for this kind of application, or is there something that I've missed?

Upvotes: 12

Views: 3487

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564433

MEF is definitely the simplest option of the three. It was really designed with this exact scenario (extensible applications) in mind.

It's actually the "plugin" mechanism used by Visual Studio, which is a WPF application. All you need to do is have your "plugin" implement an interface or derive from a known base class, and add the [Export] attribute. Provided it's assembly is added to your main application's catalog, that type can be [Import]ed by the main application in one step. There is very little work involved in making this work.

It would be my recommendation, unless there is a strong reason to go with a different option. MAF has more isolation support, but is much more difficult to use, and most of the isolation features will not be usable in a WPF application, since the UI in WPF can't really be isolated code in any case.

Upvotes: 11

Related Questions