开发者_运维问答
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 questionI'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.
- 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
- Developers implement interface and produce assemblies
- Use Assembly.Load to load in runtime.
- List types by GetTypes
- Find types that implement your interface
- Activator.CreateInstance
- Have fun
精彩评论