I have the following scenario for declaring export plugins for my application:
public abstract class PluginBase : NinjectModule
{
protected PluginBase(IDataSource source)
{
// ...
}
public override void Load()
{
Bind<PluginBase>().To(GetType());
}
}
public class RealPlugin : PluginBase
{
public RealPlugin(IDataSource source)
{
// ...
}
}
Unfortunatelly, Kernel.Load(AssemblyName) doesn't seem to detect RealPlugin as loadable element and the Load() method is never called. It works if I add an extra public constructor with no arguments to both classes. However, I actually don't want to do that because I don't want anyone to create an instance of RealPlugin without specifying the data source.
An ugly workaround seems to be to mark the parameterless constructors with [Obsolete], which at least prevents accidental usage of them.
Of course, I could also create separate classes deriving from NinjectModule to create the Bindings, but that requires another class for each of my Plugins, which is also not so nice (and prevents binding to the dynamic type of the instance, as seen above)
Anyone got an idea how such a plugin can be registered without having a public parameterless constructor?
Kernel.Load(NinjectModule)instead of usingKernel.Load(AssemblyName). - BatteryBackupUnit