简体   繁体   中英

Building a plugin system on WP8

Let's say I have got this kind of structure:

|
|-Plugins
         |-Plugin1.cs
         |-Plugin2.cs
         |-Plugin3.cs
|-PluginBase.cs
|-PluginList.cs

where each class in the Plugins folder extends from PluginBase.cs .

I need my PluginList.cs to export a list of the available plugins, so that the app can use it to make the user choose which one he wants.

Now, since this is my first experience with C#, I don't know how this works.

Searching online I found something about the Managed Extensibility Framework but I'm not sure if this is what I need.

My very raw idea is to scan the Plugin directory and list them but I don't know if C# as an equivalent to Java's Class class so I've not tried yet.

Since I'm talking about a mobile application, I also want it to be as fast as possible, so maybe this scanning method is not the best one.

Any idea?

EDIT:

So, the best thing to do is to use MEF2 but I can't make it work because Visual Studio won't let me add the assembly to the project (tried with Nuget and by manually adding the dlls).

Is there any alternative to MEF2?

Actually, MEF is exactly what you need. It is designed specifically for plugin or extensible architectures and provides a range of base functionality that you are trying to implement yourself.

The Managed Extensibility Framework (MEF) is a composition layer for .NET that improves the flexibility, maintainability and testability of large applications. MEF can be used for third-party plugin extensibility, or it can bring the benefits of a loosely-coupled plugin-like architecture to regular applications.

http://mef.codeplex.com/

This link provides a nice introduction and basic example to explain how MEF works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM