Hello
I have a main app that is going to have some plugins in the ./plugin directory.
Every plugin is a .NET dll and should have the namespace "Plugin" and a class "MainClass" implementing the IPlugin interface defined in the main app.
The problem I have is that I don't know how I could share the same interface across the main app and every plugin without a using
reference?
A part of the main app class:
object oo = Assembly.LoadFile(path).CreateInstance("Plugin.MainClass");
IPlugin pp = (IPlugin)oo; //Fails if I define the interface in the main app and the plugins
and a part of the first plugin:
namespace Plugin
{
public class MainClass : IPlugin //I cannot reference the interface in the main app?
{
public string getName()
{
return "Plugin 1";
}
}
}
You are correct in that to use an interface (or class, struct etc...) you must reference that assembly. If you do not wish to have your plugins reference the main application (which makes sense) Why not add a new assembly for this purpose? Calling it 'framework' or 'util'.
E.G
Framework Assembly - IPlugin PluginOne Assembly (references Framework) - PluginOne : IPlugin Main App Exe (references PluginOne & Framework assemblies)
You want a class library assembly that contains only the interfaces that both the main application and the plugins are built against.
One point about this:
Every plugin is a .NET dll and should have the namespace "Plugin" and a class "MainClass"
You cannot enforce the plug-in's namespace or class names unless you're the one writing them.
If you publish the interface (from a separate assembly as others have suggested), and I implement your interface, it doesn't matter if my Namespace is Plugin with class MainClass or the namespace is "TheEvilGreebo" and the class name is "IsGod".
As long as my "TheEvilGreebo.IsGod" class IMPLEMENTS your IPlugin properly, that's all that matters from your perspective as the interface designer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With