AEM: Sling model injection and annotation
A response building on “Deep diving into Sling models PT2”
This article is a response to an article by a connection of mine, Dylan Reniers: https://www.digitalum.eu/2020/06/19/deep-diving-into-sling-models-pt2/. I recommend you read the piece as it has some interesting information and because otherwise the rest of this article won’t make much sense! 😉
In the article, Dylan mentions 4 red flags in Sling Model implementation:
1. Set the defaultInjectionStrategy to optional
2. Use both SlingHttpServletRequest and Resource as adaptables
3. Use @Inject everywhere
4. No name added to the property using @Named
Here is my opinion on those red flags. If you have an opinion of your own, you can leave a comment below or reach out to me on LinkedIn to discuss 🙂
- I disagree that setting the
defaultInjectionStrategy
this is always a bad thing. - Agreed. You can get the resource from a
request
anyways so using both is redundant. - Agreed.
- Disagree-ish. It depends on context.
I won’t address point 2 since I’m in line with Dylan’s opinion, but for the other 3 points, here is a bit more detail: