plugin manager: chain child injectors for plugin dependencies
Instead of combining the modules of the plugin and all of it dependencies, create a new child injector for the plugin from a child injector comprised of the parent module(s)
This commit is contained in:
@@ -478,21 +478,39 @@ public class PluginManager
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Module pluginModule = (Binder binder) ->
|
Injector parent = RuneLite.getInjector();
|
||||||
|
|
||||||
|
if (deps.size() > 1)
|
||||||
{
|
{
|
||||||
binder.bind(clazz).toInstance(plugin);
|
List<Module> modules = new ArrayList<>(deps.size());
|
||||||
binder.install(plugin);
|
|
||||||
for (Plugin p : deps)
|
for (Plugin p : deps)
|
||||||
{
|
{
|
||||||
Module p2 = (Binder binder2) ->
|
// Create a module for each dependency
|
||||||
|
Module module = (Binder binder) ->
|
||||||
{
|
{
|
||||||
binder2.bind((Class<Plugin>) p.getClass()).toInstance(p);
|
binder.bind((Class<Plugin>) p.getClass()).toInstance(p);
|
||||||
binder2.install(p);
|
binder.install(p);
|
||||||
};
|
};
|
||||||
binder.install(p2);
|
modules.add(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a parent injector containing all of the dependencies
|
||||||
|
parent = parent.createChildInjector(modules);
|
||||||
|
}
|
||||||
|
else if (!deps.isEmpty())
|
||||||
|
{
|
||||||
|
// With only one dependency we can simply use its injector
|
||||||
|
parent = deps.get(0).injector;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create injector for the module
|
||||||
|
Module pluginModule = (Binder binder) ->
|
||||||
|
{
|
||||||
|
// Since the plugin itself is a module, it won't bind itself, so we'll bind it here
|
||||||
|
binder.bind(clazz).toInstance(plugin);
|
||||||
|
binder.install(plugin);
|
||||||
};
|
};
|
||||||
Injector pluginInjector = RuneLite.getInjector().createChildInjector(pluginModule);
|
Injector pluginInjector = parent.createChildInjector(pluginModule);
|
||||||
pluginInjector.injectMembers(plugin);
|
pluginInjector.injectMembers(plugin);
|
||||||
plugin.injector = pluginInjector;
|
plugin.injector = pluginInjector;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user