How to make an application a plugin without a separate DLL for the plugin interface?

The traditional procedure for developing plug-in architecture, apparently, consists in creating a separate DLL containing only a common interface, which all plug-ins will implement, and force both the main application and the plug-ins.

I am trying to do the same, but without a separate DLL. One obvious way is for all plugins to be dependent on the main application, but this was hardly a pretty good solution.

Can you come up with a more beautiful solution? Ideally, there would be no dll binding interface; if this is not possible, it would be pretty cool if a user who does not plan to run plugins would not need to load the DLL plug-in at all. Taht, only those who run plugins need a DLL interface.

+3
source share
3 answers

You can load the assembly and access its types through Reflection. There are several examples here: http://www.csharp-examples.net/reflection-examples/ , and I extracted some of the most interesting ones:

Assembly testAssembly = Assembly.LoadFile(@"c:\Test.dll");
Type calcType = testAssembly.GetType("Test.Calculator");
object calcInstance = Activator.CreateInstance(calcType);

// Get property value
PropertyInfo numberPropertyInfo = calcType.GetProperty("Number");
double value = (double)numberPropertyInfo.GetValue(calcInstance, null);

....

// invoke public instance method: public void Clear()
calcType.InvokeMember("Clear",
     BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public,
     null, calcInstance, null);

, , , , . , , , .

, , , DLL.

+2

MEF System.Object () .

, - . , , .

DLL , . , . "" - .

+3

- Reflection. () , Invoke.

.NET 4 - dynamic. , , , .

, , , , .

+1

All Articles