AEM: Sling model injection and annotation

A response building on “Deep diving into Sling models PT2

Theo Pendle
5 min readJun 21, 2020

--

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 🙂

  1. I disagree that setting the defaultInjectionStrategy this is always a bad thing.
  2. Agreed. You can get the resource from a request anyways so using both is redundant.
  3. Agreed.
  4. 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:

Setting the defaultInjectionStrategy to optional

--

--

Theo Pendle

Software engineer hoping to learn and inspire by sharing my experiences 🙂 Reach out to me on LinkedIn: https://www.linkedin.com/in/theo-pendle-1630a52a