Nope, it is not!
Following are the Injectors Available:
Scripting Bindings
ValueMap (We will specifically talk about this annotation on this post)
Child Resource
Request Attribute
Resource path
OSGi service
Context-Aware Configuration
Self
Sling Object
@Inject iterates through all available injectors and injects the first non-null value provided by an injector. This lead to unpredictable behavior, although the order is well-defined. Also, this turned out to be a performance bottleneck, especially if (optional) injections were not successful, and then all other injectors have to be tried.
Whereas, @ValueMapValue injects ValueMap value taken from the adapted resource (either taking from the adapted resource or the resource of the adapted SlingHttpServletRequest). If the name is not set the name is derived from the method/field name.
Thus, usage of @ValueMapValue is preferred as it specifically injects the ValueMap injector and doesn't iterate through all the available injectors.
That's all for today! If you've found this blog post informative or helpful, I’d greatly appreciate it if you could give it a like. It keeps me motivated 💛
Enjoying my ad-free blog? Support by buying me a coffee! I've kept this space ad-free, sponsoring it myself to maintain its purity. Your contribution would help keep the site afloat and ensure quality content. Thanks for being part of this ad-free community.
Comentários