aemsling-models

AEM, Sling Models and Resource Resolver


I'm looking for an answer on this and can't find one either negatively or positively.

If we get an instance of ResourceResolver through sling models injection, who is responsible for closing that resource resolver. Do we have to close it, or does the sling model framework own the resource resolver and handle this for us?

In short are we controlling the resource resolver's lifecycle or Sling Models?

I ask as no Sling Model code example I've found closes the resource resolver, and no article seems to even mention this.

Thanks in advance.


Solution

  • The way model works is in the scope of Sling Request or Resource, in either case ResourceResolver is in the scope of request and needs no explicit handling of it. It gets handled along with request commit.
    If u explicitly close the resource resolver obtained in slingModel from request or resource it will lead to ResponseAlreadyCommited or IllegalStateException.

    The only scenario where in you should worry about closing a resourceResolver is if you explicitly created one from the ResourceResolverFactory.