Since we want to be able to return multiple plugins having the same supertype, we need a way to specify a plugin for dependency injection via his name.
Using javax.inject.Named can do the job.
Currently:
import javax.inject.Inject;
public class MyPlugin {
@Inject
public MyPlugin(Callable otherPlugin) { // I can't inject a second, different Callable
// stuff
}
}
Goal:
import javax.inject.Inject;
import javax.inject.Named;
public class MyPlugin {
@Inject
public MyPlugin(
@Named("firstPlugin")
Callable firstPlugin,
@Named("secondPlugin")
Callable secondPlugin
) {
// stuff
}
}
The resolution will happen as follow:
Check if a parameter has the @Named annotation.
If so, retrieve the dependency by name. If not found, throw MissingDependencyException.
If it doesn't have the annotation, check the parameter type.
Retrieve the dependency by type. Following #11, a list will be returned. This list should contain only one element, otherwise, throw NoUniquePluginFoundException (new annotation).
Since we want to be able to return multiple plugins having the same supertype, we need a way to specify a plugin for dependency injection via his name. Using
javax.inject.Named
can do the job.Currently:
Goal:
The resolution will happen as follow:
@Named
annotation. If so, retrieve the dependency by name. If not found, throwMissingDependencyException
.NoUniquePluginFoundException
(new annotation).