Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plugin pattern in C#

Problem:
I am constructing a framework which accepts a file, translates it and executes it. The framework should be able to handle any type of file, to this end i have provided a method of uploading a DLL containing classes and methods for translating and executing a file. What i am looking for, is the best way to define the plugin interface

Solution A:
Define a set of interfaces which are publicly available. Plugins should implement these interfaces.

Solution B:
Define some abstract classes which are publicly available. Plugins should inherrit and override the abstract methods on these classes.

Solution C: rcravens
Pass interfaces around inside the code, create an abstract class which is publicly available to allow for plugin extensibility. Chosen
This solution was chosen ahead of interface only because it enables basic implementation (handy in this case). It was chosen ahead of abstract class only because it enables mocking within the code. The composition frameworks are excellent, but a bit over the top for something as lightweight as this application where only limited extensibility is desired.

Solution D: Jay and Chris Shain
Implement a composition framework (such as Managed Extensibility Framework(MEF)) and build around it

If any new solutions appear, i will add them to this list. The answer will go to the person who is best able to justify their solution (possibly with advantages and limitation)

Thanks in advance,
Tech Test Dude

like image 668
David Colwell Avatar asked Aug 16 '11 00:08

David Colwell


People also ask

What is a plugin in C?

In this paper, a plugin is code that can become part of a program under that program's control. For C and C++ programs plugins are typically implemented as shared libraries that are dynamically loaded (and sometimes unloaded) by the main program.

What is plugin framework?

The plugin framework is a NuGet package that allows you to customise and extend a .NET application. Plugins are loaded at runtime from a catalogue which can be a local source or via NuGet. Supports all the current . NET Core based applications, ranging from Blazor to ASP.NET Core and to Console, WPF and Windows Forms.

How do plugin systems work?

plug-in, also called add-on or extension, computer software that adds new functions to a host program without altering the host program itself. Widely used in digital audio, video, and Web browsing, plug-ins enable programmers to update a host program while keeping the user within the program's environment.


1 Answers

What you are writing sounds suspiciously like what Managed Extensibility Framework supports: http://mef.codeplex.com/. Maybe just use that and avoid re-inventing the wheel?

like image 63
Chris Shain Avatar answered Sep 28 '22 11:09

Chris Shain