G
Guest
Hi,
[ BTW I'm using C# ]
I'm trying to implement a Plugin architecture where I have a single UI
framework, and then load dll components into that framework.
At the moment I'm constructing the Plugin loading mechanism, I've created a
plugin interface ( that the plugin clients must implement ) and a pluginhost
interface ( thart the ui framework plugin manager must imlpement ).
When the UI framework loads the plugin assembly it checks the types in the
assembly to ensure it supports the plugin interface, if it does then it
constructs an instance of this type and casts it to the plugin interface type.
If I create a source file with these interfaces in and link this file ( i.e.
share the file )into each project then I get a CastException - in
CreatePluginInstance - when I cast to the plugin interface type. If I
implement this interface in a separate dll and then reference this in the
framework and the pluginclient, then the cast succeeds.
I suppose this works, but I would rather keep the number of dlls to a
minimum, and hoped to be able to get away with just sharing the interface
source file. Is this possible ??, or do I need to implement it this way ??
regards
Rich.
CODE:
Interface.....
namespace PluginInterface
{
public interface IPlugin
{
IPluginHost Host{ get;set; }
}
public interface IPluginHost
{
bool Register(IPlugin ipi);
}
}
PluginCreation and Cast...
Assembly objAssembly = Assembly.LoadFrom(_strPath);
foreach (Type iterTypes in objAssembly.GetTypes())
{
foreach (Type iterInterfaces in
objIterGetAssemblyTypes.GetInterfaces())
{
if
(iterInterfaces.Equals(typeof(PluginInterface.IPlugin)))
{
CreatePluginInstance(iterInterfaces);
}
}
}
}
public void CreatePluginInstance( Type _assemblyType )
{
PluginInterface.IPlugin sui_Plugin =
(PluginInterface.IPlugin)Activator.CreateInstance(_assemblyType);
}
[ BTW I'm using C# ]
I'm trying to implement a Plugin architecture where I have a single UI
framework, and then load dll components into that framework.
At the moment I'm constructing the Plugin loading mechanism, I've created a
plugin interface ( that the plugin clients must implement ) and a pluginhost
interface ( thart the ui framework plugin manager must imlpement ).
When the UI framework loads the plugin assembly it checks the types in the
assembly to ensure it supports the plugin interface, if it does then it
constructs an instance of this type and casts it to the plugin interface type.
If I create a source file with these interfaces in and link this file ( i.e.
share the file )into each project then I get a CastException - in
CreatePluginInstance - when I cast to the plugin interface type. If I
implement this interface in a separate dll and then reference this in the
framework and the pluginclient, then the cast succeeds.
I suppose this works, but I would rather keep the number of dlls to a
minimum, and hoped to be able to get away with just sharing the interface
source file. Is this possible ??, or do I need to implement it this way ??
regards
Rich.
CODE:
Interface.....
namespace PluginInterface
{
public interface IPlugin
{
IPluginHost Host{ get;set; }
}
public interface IPluginHost
{
bool Register(IPlugin ipi);
}
}
PluginCreation and Cast...
Assembly objAssembly = Assembly.LoadFrom(_strPath);
foreach (Type iterTypes in objAssembly.GetTypes())
{
foreach (Type iterInterfaces in
objIterGetAssemblyTypes.GetInterfaces())
{
if
(iterInterfaces.Equals(typeof(PluginInterface.IPlugin)))
{
CreatePluginInstance(iterInterfaces);
}
}
}
}
public void CreatePluginInstance( Type _assemblyType )
{
PluginInterface.IPlugin sui_Plugin =
(PluginInterface.IPlugin)Activator.CreateInstance(_assemblyType);
}