Need help in understanding Sling Models Annotations like @Model, @Inject, and @PostConstruct | Community
Skip to main content
Level 2
Sep 6, 2023 9:58 AM UTC
Solved

Need help in understanding Sling Models Annotations like @Model, @Inject, and @PostConstruct

What are use of @Model, @586265, and @PostConstruct annotations in Adobe Experience Manager (AEM)? Help me explain this in details. I'd like to gain a deeper understanding of how these annotations work and their practical applications when creating Sling Models in AEM. Any insights or examples would be greatly appreciated!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
aanchal-sikka
aanchal-sikkaAccepted solution
New Participant
Sep 6, 2023 7:03 PM UTC

Hello @aem101 

 

For @Model & @PostConstruct, please refer to the documentation shared by @estebanbustamante 

 

@Inject is rarely used in Sling Models now. There are many alternatives are available which are specific to the needs.

Please refer to AEM Sling Model Injectors Annotations Cheat Sheet Reference Guide - Sourced Code

They have beautifully explained the mappings between old @Inject way to new recommended annotations like 

  1. @ScriptVariable
  2. @ValueMapValue
  3. @ResourcePath
  4. @ChildResource
  5. @RequestAttribute
  6. @OSGiService
  7. @Self
  8. @SlingObject
Aanchal Sikka

3 replies

aanchal-sikka
aanchal-sikkaAccepted solution
New Participant
Sep 6, 2023 7:03 PM UTC

Hello @aem101 

 

For @Model & @PostConstruct, please refer to the documentation shared by @estebanbustamante 

 

@Inject is rarely used in Sling Models now. There are many alternatives are available which are specific to the needs.

Please refer to AEM Sling Model Injectors Annotations Cheat Sheet Reference Guide - Sourced Code

They have beautifully explained the mappings between old @Inject way to new recommended annotations like 

  1. @ScriptVariable
  2. @ValueMapValue
  3. @ResourcePath
  4. @ChildResource
  5. @RequestAttribute
  6. @OSGiService
  7. @Self
  8. @SlingObject
Translate
Aanchal Sikka
EstebanBustamante
New Participant
Sep 6, 2023 1:46 PM UTC

Hi

 

In my opinion, there is nothing better than the official source, you can learn and understand about sling models on the official sling site. Also, there is a specific section talking about the Available Injectors with some examples, you can read more here: https://sling.apache.org/documentation/bundles/models.html#available-injectors 

 

Translate
Esteban Bustamante
Mahedi_Sabuj
New Participant
Sep 6, 2023 10:36 AM UTC
Mahedi Sabuj