アプリケーションをどのように設計するか、実際にはFirefoxやChromeなどのアドオンをダウンロードして使用できるアプリケーションを知りたいです??!! .Netでどのように行うのですか???
3 に答える
他のユーザーがアプリのアドオンを作成できるようにする方法は?
1>DLL
を持つ を作成しますinterface
。これinterface
は、他の人に定義および実装してもらいたい一連のメソッド、プロパティ、イベントを定義します。
プラグイン開発者は、このインターフェイスを定義する必要があります。この DLL は、アプリとプラグイン開発者に必要です。
2>プラグイン開発者は、その共有を使用しDLL
、メソッドまたはプロパティを定義することでインターフェイスを実装します。
3>アプリはそのプラグインをロードして共有 DLL にキャストしinterface
、必要なメソッド、プロパティ、つまりインターフェイスで定義されたものを呼び出します。
アプリはプラグインをどのように取得しますか?
folder
を検索する場所を作成します。これは、他の人がplugins
いるフォルダですまたは.plugins
installed
placed
例
これはあなたの共有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
}
}
}
Managed Extensibility Framework (MEF) を使用する必要があります。
MEF を使用します。
Managed Extensibility Framework (MEF) は、.NET の新しいライブラリであり、アプリケーションとコンポーネントの再利用を大幅に促進します。MEF を使用すると、.NET アプリケーションは、静的にコンパイルされたものから動的に構成されたものへと移行できます。拡張可能なアプリケーション、拡張可能なフレームワーク、およびアプリケーションの拡張機能を構築している場合は、MEF が適しています。
MEF の便利なリンク。
http://www.codeproject.com/Articles/376033/From-Zero-to-Proficient-with-MEF
http://www.codeproject.com/Articles/232868/MEF-Features-with-Examples