Let’s look at an example. If we have an interface named Helper and an implementing class HelperImpl, all we need to do to make it available for injection, is to use @Named annotation on the implementing class:
To have the Helper implementation injected into another class (in this case a REST resource), we’ll annotate it’s constructor with @Inject:
The example above works when injecting an object from the same plugin. If you would like to inject an object from Jira itself (or another plugin), add the @ComponentImport annotation to the constructor parameter.
For example, if we want to use the ApplicationProperties in our class, we can do it like this:
And that’s all. Just use @Named on your components, @Inject on constructors that use your components and @ComponentImport when importing stuff outside your plugin.
Comments