MEF Question
-
Currently I'm loading plugins like this
private void LoadPlugins()
{
var pluginPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
var directoryCatalog = new DirectoryCatalog(pluginPath);
var container = new CompositionContainer(directoryCatalog);
// Problem: This syntax required the interface to be compiled into this app
var plugins = container.GetExportedValues();
}As the comment says, the interface is required to be compiled into this app. Is there a way to load MEF plugins without the host app knowing about the interface?
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
-
Currently I'm loading plugins like this
private void LoadPlugins()
{
var pluginPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
var directoryCatalog = new DirectoryCatalog(pluginPath);
var container = new CompositionContainer(directoryCatalog);
// Problem: This syntax required the interface to be compiled into this app
var plugins = container.GetExportedValues();
}As the comment says, the interface is required to be compiled into this app. Is there a way to load MEF plugins without the host app knowing about the interface?
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
Caveat - I have not used MEF or plug ins. Uhm that does not seem to make sense, the host application needs to code against the functionality of the plug in, hence the required interface. I am scratching my head trying to figure out a use case for not having an interface for the plug in. I will be interested in other responses :-O
Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP
-
Currently I'm loading plugins like this
private void LoadPlugins()
{
var pluginPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
var directoryCatalog = new DirectoryCatalog(pluginPath);
var container = new CompositionContainer(directoryCatalog);
// Problem: This syntax required the interface to be compiled into this app
var plugins = container.GetExportedValues();
}As the comment says, the interface is required to be compiled into this app. Is there a way to load MEF plugins without the host app knowing about the interface?
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
I don't think you can get rid of the interface. How is the host app supposed to know how to call the methods in the plug-in, and what they do, if the plug-in doesn't implement some kind of interface?
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
Currently I'm loading plugins like this
private void LoadPlugins()
{
var pluginPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
var directoryCatalog = new DirectoryCatalog(pluginPath);
var container = new CompositionContainer(directoryCatalog);
// Problem: This syntax required the interface to be compiled into this app
var plugins = container.GetExportedValues();
}As the comment says, the interface is required to be compiled into this app. Is there a way to load MEF plugins without the host app knowing about the interface?
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
I can see where you are going with this but you have the problem inverted. It sounds like you have a contract that you have created in a plugin assembly and you are trying to use MEF to load that assembly, which has already been linked with the application. Rather than doing this, you would normally have the interface defined in an assembly that just contains contracts. Both the plugins and the application host will be linked with that assembly but they will not share any code and the application host does not have to know anything about the plugins other than that they share an interface. That way you keep them both from knowing about each other, as they rely on the intermediary.
This space for rent