开发者

Creating my own plug-ins for my own project in C# [closed]

开发者 https://www.devze.com 2022-12-21 21:26 出处:网络
Closed. This question needs to be more focused. It is not currently accepting answers. 开发者_运维问答
Closed. This question needs to be more focused. It is not currently accepting answers.
开发者_运维问答

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 7 years ago.

Improve this question

I'm working on a project in C#, it's about E-learning.This project should use plug-ins as its main inputs, it can't function without them. I have no idea how can I work with plug-ins, I know nothing about how can a plug-in compile inside my program, or how can I install them inside my application. I'm asking here about references, or any useful ideas that can help me with this.


Start by creating a Plug-In Interface:

public interface IPlugIn
{
    // Your stuff here
}

You can then distribute your interface to the developers working on the plugins.

When your application starts up, it can load all Plug-In assemblies dynamically, then work with them through the IPlugIn interface without needing to know the internals of each one.

UPDATE

I actually found an article that goes into the process I described in more depth with more ellaborate examples. You can check it out here:

Writing Plugin-Based Applications in .NET

And an added bonus...it comes with Code Samples!


if your plugin is not too complex you can avoid using extensibility frameworks like MEF.

  1. You define contract for plugin. It should be public interface, or may be class with abstract/virtual methods. You should move it to separate assembly and distribute to plugin developers
  2. Developers implement interface and produce assemblies
  3. Use Assembly.Load to load in runtime.
  4. List types by GetTypes
  5. Find types that implement your interface
  6. Activator.CreateInstance
  7. Have fun
0

精彩评论

暂无评论...
验证码 换一张
取 消