[ 
https://issues.apache.org/jira/browse/SLING-6785?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15978813#comment-15978813
 ] 

Jason E Bailey commented on SLING-6785:
---------------------------------------

I have concerns with the utility of this. It would be adding a layer of 
complexity to the design that would only benefit a very narrow range of models 
and the only scope that makes sense in my understanding of Sling would be the 
'request' scope. 

An example of potential confusion is a model that adapts from a 
SlingHttpServletRequest but retrieves the current resource from it. In a 
component I could call slingRequest.adaptTo(MyModel.class) with the expectation 
that the returned model represents my component. Only to discover that it 
doesn't. It returns the model from a prior adaption, same component, different 
data.  This would be a violation of expectations. Not to say that there 
shouldn't be an easy way to transfer data through the hierarchy of includes and 
forwarding. I just don't think caching of the models is it.

> Add support for scoped lifecycle of sling models
> ------------------------------------------------
>
>                 Key: SLING-6785
>                 URL: https://issues.apache.org/jira/browse/SLING-6785
>             Project: Sling
>          Issue Type: New Feature
>          Components: Extensions
>            Reporter: Christophe Jelger
>            Priority: Minor
>
> Similar to the scopes of JEE beans 
> (http://docs.oracle.com/javaee/6/tutorial/doc/gjbbk.html), it would be nice 
> to have the possibility to set a scope for sling models.
> For example, a sling model instance could be reused for all the components 
> within the same HTTP request, thus avoiding that multiple instances of the 
> "same" model are created.
> This could be an attribute of the {{@model}} annotation, for example 
> something like:
> {{@model(scope="request")}}
> The {{request}} scope sounds straightforward for a sling model adapted from a 
> request.
> For models adapted from a resource, there are scenarios where the resource 
> itself is not relevant once the model has been instantiated, so it would 
> still be useful to be able to obtain the same model instance for different 
> components and resources within the same HTTP request.
> We could possibly have the same scopes than the JEE beans scope: {{request}}, 
> {{session}}, and {{application}}.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to