简体   繁体   English

在WP8上构建插件系统

[英]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 . 其中Plugins文件夹中的每个类都从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. 我需要我的PluginList.cs导出可用插件的列表,以便应用程序可以使用它来使用户选择他想要的插件。

Now, since this is my first experience with C#, I don't know how this works. 现在,由于这是我第一次使用C#,因此我不知道它是如何工作的。

Searching online I found something about the Managed Extensibility Framework but I'm not sure if this is what I need. 在线搜索时,我发现了有关Managed Extensibility Framework的一些信息,但是我不确定这是否是我所需要的。

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. 我非常原始的想法是扫描Plugin目录并列出它们,但是我不知道C#是否等效于Java的Class类,因此我还没有尝试过。

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). 因此,最好的办法是使用MEF2,但我无法使其正常工作,因为Visual Studio不允许我将程序集添加到项目中(尝试使用Nuget并手动添加dll)。

Is there any alternative to MEF2? 除了MEF2,还有其他选择吗?

Actually, MEF is exactly what you need. 实际上,MEF正是您所需要的。 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)是.NET的组合层,可提高大型应用程序的灵活性,可维护性和可测试性。 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. MEF可以用于第三方插件的可扩展性,也可以将松散耦合的类似插件的体系结构的优点带给常规应用程序。

http://mef.codeplex.com/ http://mef.codeplex.com/

This link provides a nice introduction and basic example to explain how MEF works. 链接提供了一个很好的介绍和基本示例,以解释MEF的工作原理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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