【问题标题】:Design add-on base Application设计附加基础应用程序
【发布时间】:2012-11-19 10:40:15
【问题描述】:

我想知道如何设计应用程序,实际上是 Firefox 或 Chrome 等应用程序,您可以为它们下载附加组件并使用 ??!! 在.Net中怎么做???

【问题讨论】:

    标签: c# .net add-on


    【解决方案1】:

    您应该使用托管可扩展性框架 (MEF)。

    http://mef.codeplex.com/

    http://msdn.microsoft.com/en-us/library/dd460648.aspx

    【讨论】:

      【解决方案2】:

      如何允许其他人为您的应用制作附加组件?

      1>您创建一个DLL,其中有一个interface。这个interface 定义了一组您希望其他人定义和实现的方法、属性和事件。

      插件开发者需要定义这个接口。这个DLL是你的应用程序和插件开发者需要的..

      2>插件开发者将使用共享的DLL 并通过在其中定义方法或属性来实现接口。

      3>您的应用现在将加载该插件并将其转换为共享 DLL 的 interface,然后调用所需的方法、属性,即接口中定义的任何内容..

      您的应用如何获取插件?

      您创建一个folder,您将在其中搜索plugins。这是其他plugins 将是installedplaced 的文件夹。


      例子

      这是你的共享 dll

      //this is the shared plugin
      namespace Shared 
      {
          interface IWrite 
          {
              void write();
          }
      }
      

      插件开发者

      //this is how plugin developer would implement the interface
      using Shared;//<-----the shared dll is included
      namespace PlugInApp 
      {
          public class plugInClass : IWrite //its interface implemented
          {
              public  void write() 
              {
                  Console.Write("High from plugInClass");
              }
          }
      }
      

      这是你的程序

      using Shared;//the shared plugin is required for the cast
      class Program
          {
              static void Main(string[] args)
              {
                  //this is how you search in the folder
                  foreach (string s in Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*PlugIn.dll"))//getting plugins in base directory ending with PlugIn.dll
                  {
                      Assembly aWrite = Assembly.LoadFrom(s);
                      //this is how you cast the plugin with the shared dll's interface
                      Type tWrite = aWrite.GetType("PlugInApp.plugInClass");
                      IWrite click = (IWrite)Activator.CreateInstance(tWrite);//you create the object
                      click.write();//you call the method
                  }
              } 
          }
      

      【讨论】:

      • 干得好,你能澄清一下吗,例如我通过 vb.net 开发了会计软件,我想通过在我的应用程序中添加插件来添加备份功能以从其 sql 数据库中进行备份,那么应该如何我想出那个?
      • @franchescototti 您必须对您的会计应用程序进行一些更改才能实现插件搜索和执行功能..
      • 如果您知道 Windows 窗体应用程序的任何示例,请告诉我?
      【解决方案3】:

      使用 MEF。

      托管可扩展性框架 (MEF) 是 .NET 中的一个新库 从而可以更好地重用应用程序和组件。使用 MEF, .NET 应用程序可以从静态编译转变为 动态组成。如果您正在构建可扩展的应用程序, 可扩展框架和应用程序扩展,那么 MEF 适合您。

      MEF 的有用链接。

      http://mef.codeplex.com/

      http://www.codeproject.com/Articles/376033/From-Zero-to-Proficient-with-MEF

      http://www.codeproject.com/Articles/232868/MEF-Features-with-Examples

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-07
        • 1970-01-01
        • 1970-01-01
        • 2019-01-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多