wooncherk wrote:If your plugin did not check for PluginDescriptor.Installed before running code, nopCommerce will still run the plugin code. As far as I know, plugins are loaded whether or not they are installed. This makes sense because to perform some plugin actions, we need the help of the plugin itself (for example Install method is written in the plugin itself). So even it is not installed, it has to be loaded. And because it is loaded, any methods that you've written will run, unless you check for PluginDescriptor.Installed explicitly. :)
Thanks for your insightful reply. Where do I use PluginDescriptor.Installed to check if my plugin is installed? In the DependencyRegistrar?
In all your methods that you want disabled when not installed. :)
I have many custom implementations (usually services) of the nopCommerce core interfaces. If I put
PluginDescriptor.Installed on all the implementation member methods, they are exceptions being thrown because there is no fallback methods to serve the request when it is consumed by nopCommerce.
So I think I should go back to the point of origin, in preventing the implementations from ever being registered by the DependencyRegistrar's Register method if the plugin is not installed.
So my code for the DependencyRegistrar is something like
public class DependencyRegistrar : IDependencyRegistrar {
public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder) {
var pluginDescriptor = _pluginFinder.GetPluginDescriptorBySystemName("Misc.pluginname");
if (pluginDescriptor != null) {
//Register dependencies
}
}
}
So now the question is, how to resolve
_pluginFinder? DependencyRegistrar doesn't support constructor injection.
Or do I use
EngineContext.Current.Resolve<IPluginFinder>() to resolve it? But wouldn't this create a dependency on the IOC container which makes conducting unit testing more difficult? I've seen this used in Views which is okay since unit testing doesn't involve Views.