Edit online

Dependency Injection for Plugins

If you want to share a single instance of a certain class between plugin extensions and custom operations (to prevent instances from being repeated), you can declare a <context> element in your plugin.xml file:
<context class="my.package.ContextClass"/>
Important: The my.package.ContextClass class should have a no-arguments constructor that will be called when the class is instantiated.
This will result in an instance being automatically generated. You can access this instance in an extension class by defining a field of that type and annotated with the ro.sync.exml.plugin.PluginContext annotation:
@PluginContext
ContextClass contextInstance;

The defined field is automatically populated with the single instance.