2012-12-01 2 views

답변

2

어떻게 다른 사람들이 앱의 기능을 추가 할 수 있도록?

1>interface이있는 DLL을 만듭니다.이 interface은 다른 사람들이 정의하고 구현할 수있는 일련의 메서드, 속성, 이벤트를 정의합니다.

플러그인 개발자는

2

이> 플러그인 개발자가 DLL을 한 것으로 사용하고 메서드 나 속성을 정의하여 인터페이스를 구현하는 것입니다 ..이 interface.This DLL 앱 및 플러그인 개발자가 필요 정의 할 필요가 그 안에.

3> 앱은 이제

어떻게 응용 프로그램은 플러그인을 가져올 것입니다 .. 속성은 인터페이스에 정의 된 것을 즉 그 플러그인을로드하고 공유 DLL의 interface에 캐스팅 다음 원하는 메서드를 호출 할 것인가?

당신은 당신이 plugins .This를 검색 할 것 folder 다른 사람 pluginsinstalled 또는 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"); 
     } 
    } 
} 

플러그인 devloper

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 
      } 
     } 
    } 
+0

좋은 일, 당신은 내가 vb.net에 의해 회계 소프트웨어를 개발, 예를 들어, 저를 지우고 나는 그것의 SQL 데이터베이스에서 백업을 수행하는 백업 기능을 추가 할 수 있습니다 내 applcation에 플러그인을 추가하여 어떻게해야합니까? –

+0

@franchescototti 플러그인 검색을 구현하고 기능을 실행하려면 회계 응용 프로그램을 일부 변경해야합니다. – Anirudha

+0

Windows 양식 응용 프로그램에 대한 샘플을 알고 있다면 알려주십시오. –

0

MEF를 사용하십시오.

는 관리 확장 성 프레임 워크 (MEF)은 응용 프로그램 및 구성 요소의 큰 재사용을 가능하게 .NET 의 새로운 라이브러리입니다. MEF를 사용하면 .NET 응용 프로그램은 정적으로 컴파일되지 않도록 동적으로 구성된 으로 변경할 수 있습니다. 확장 가능한 응용 프로그램을 구축하려는 경우 확장 가능한 프레임 워크와 응용 프로그램 확장을 사용하면 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