I don't think both are equivalent. I was getting an exception with @ValuemapValue but it is gone when I used @inject
Could you please explain the difference?
Solved! Go to Solution.
Lets explore with an example of @inject v/s @ValueMapValue
@inject is a general-purpose annotation that retrieves values from various injectors, while @ValueMapValue is an injector-specific annotation designed to fetch values from the ValueMap injector.
When an injected value is exclusively available from a single injector, @inject and @ValueMapValue will behave the same. However, if a property can be provided by multiple injectors (e.g., script-binding and ValueMap), they may inject different values.
It’s advisable to prefer injector-specific annotations like @ValueMapValue or @ChildResource over @inject. This is because value injection occurs at runtime, and using @inject can introduce ambiguity, requiring the framework to make educated guesses. When using @ValueMapValue, especially in the context of retrieving properties from the ValueMap, the process is automatic, resulting in less code to write and increased clarity.
For more details on how annotations affect performance, refer to Sling Model Performance by Jörg Hoh
Lets explore with an example of @inject v/s @ValueMapValue
@inject is a general-purpose annotation that retrieves values from various injectors, while @ValueMapValue is an injector-specific annotation designed to fetch values from the ValueMap injector.
When an injected value is exclusively available from a single injector, @inject and @ValueMapValue will behave the same. However, if a property can be provided by multiple injectors (e.g., script-binding and ValueMap), they may inject different values.
It’s advisable to prefer injector-specific annotations like @ValueMapValue or @ChildResource over @inject. This is because value injection occurs at runtime, and using @inject can introduce ambiguity, requiring the framework to make educated guesses. When using @ValueMapValue, especially in the context of retrieving properties from the ValueMap, the process is automatic, resulting in less code to write and increased clarity.
For more details on how annotations affect performance, refer to Sling Model Performance by Jörg Hoh
Hi @vineetham123
Kindly go through this https://cqdump.joerghoh.de/2022/11/28/sling-model-performance/ by @joerghoh
This is best documentation I've come across this topic so far.
Regards,
Arpit Varshney