Mike
Mike

Reputation: 850

How to create and integrate Plugin for a WPF application

I've been looking everywhere for an example or something like this, without any luck so i hope someone here can put me in the right direction.

I have a WPF application that i want to build plugins/DLC/add-in (not sure what the right word is to search on when it is WPF so i'll use Plugin).

I haven't build any plugins yet, because i thought there might be a smart nuget package or a pattern to use.

So essentially i want something that are not as tedious as (I know this is so simplified...):

if(myFolderPath contains "plugin.dll")
{
    AddAMenuButtonWithThePlugin();
}

I'm hoping for maybe some kind of AnnotationMethod like:

[UseThisDll("plugin.dll")]
private void AddAMenuButtonWithThePlugin(){...}

If you have had a similar task before i would like to hear how you solved this as i don't find my own ideas that easy for me to pull off.

Basically i have multiple PC's with the WPF that are using Squirrel.Windows for the install and update.

However i have some plugins that maybe only some of the PC's should have.

Any good advice? Basically i want to add a button to a page that will lead it to the DLC page.

Upvotes: 1

Views: 1814

Answers (1)

user3188639
user3188639

Reputation:

You can use MEF for this.

There are a few versions of MEF:

  • System.ComponentModel.Composition. It's a part of .NET framework and also available as a Nuget package.
  • System.Composition, which is a lightweight version. It doesn't allow for a dynamic recomposition, but it's faster than the first one. The Nuget package is also available.
  • VS MEF which is implementation used by Visual Studio. It can reuse parts from the other two libraries. GitHub repo is here.

Upvotes: 2

Related Questions