[jira] [Commented] (SLING-6785) Add support for scoped lifecycle of sling models

2017-05-11 Thread Christophe Jelger (JIRA)

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

Christophe Jelger commented on SLING-6785:
--

[~justinedelson] Thx for the feature, I could finally test it today, works 
perfectly as expected. Cool stuff!

> 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
>Assignee: Justin Edelson
>Priority: Minor
> Fix For: Sling Models API 1.3.4, Sling Models Impl 1.4.0
>
> Attachments: SLING-6785.diff, SLING-6785.diff
>
>
> 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)


[jira] [Commented] (SLING-6785) Add support for scoped lifecycle of sling models

2017-04-24 Thread Konrad Windszus (JIRA)

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

Konrad Windszus commented on SLING-6785:


While in general I think this feature is useful I have some remarks on the patch
# It is only used with {{Adaptable.adaptTo()}} but not with the 
{{ModelFactory}} approach, I think both should behave more or less the same. 
Otherwise this feature would not be available in HTL scripts due to the 
dedicated use provider added in https://issues.apache.org/jira/browse/SLING-4447
# Supporting a different scope than the lifetime of the adaptable is very 
dangerous and should therefore not be supported. Hence I would call the 
attribute rather {{cached}}.
# the javadoc of the scope/cached element in the model annotation should be 
clarified


> 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
> Attachments: SLING-6785.diff
>
>
> 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)


[jira] [Commented] (SLING-6785) Add support for scoped lifecycle of sling models

2017-04-21 Thread Justin Edelson (JIRA)

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

Justin Edelson commented on SLING-6785:
---

bq. if the user does not set 'scope="adaptable"' and the developer expects that 
he gets a new model on each adaptTo call it would be very puzzling if it is 
cached anyway because the adaptable extends SlingAdaptable. and for the 
developer it is often not transparent if the adaptable extends SlingAdaptable 
or not.

Right, but that's the current behavior. So it sounds like we primarily need to 
document that not setting {{scope="adaptable}} doesn't disable any other 
caching. Or something like that.

> 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
> Attachments: SLING-6785.diff
>
>
> 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)


[jira] [Commented] (SLING-6785) Add support for scoped lifecycle of sling models

2017-04-21 Thread Stefan Seifert (JIRA)

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

Stefan Seifert commented on SLING-6785:
---

{quote}
if we add a scoping/caching support via @Model annotation we have to make sure 
that does not mix up with the SlingAdaptable caching implementation.
> Do you have a specific concern from an implementation standpoint? Or is this 
> just about education/documentation?
{quote}

if the user does not set 'scope="adaptable"' and the developer expects that he 
gets a new model on each adaptTo call it would be very puzzling if it is cached 
anyway because the adaptable extends SlingAdaptable. and for the developer it 
is often not transparent if the adaptable extends SlingAdaptable or not.

> 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
> Attachments: SLING-6785.diff
>
>
> 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)


[jira] [Commented] (SLING-6785) Add support for scoped lifecycle of sling models

2017-04-21 Thread Justin Edelson (JIRA)

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

Justin Edelson commented on SLING-6785:
---

bq. but this does not seem to apply to current SlingHttpServletRequest 
implementation. but the JCR resource implementation extends AbstractResource 
which extends SlingAdaptable. 

Right, because SlingHttpServletRequestImpl extends HttpServletReqeustWrapper.

bq. if we add a scoping/caching support via @Model annotation we have to make 
sure that does not mix up with the SlingAdaptable caching implementation.

Do you have a specific concern from an implementation standpoint? Or is this 
just about education/documentation?

> 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
> Attachments: SLING-6785.diff
>
>
> 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)


[jira] [Commented] (SLING-6785) Add support for scoped lifecycle of sling models

2017-04-21 Thread Stefan Seifert (JIRA)

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

Stefan Seifert commented on SLING-6785:
---

please note that if the adaptable extends SlingAdaptable ,there is already 
today an implicit caching:
https://github.com/apache/sling/blob/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/SlingAdaptable.java#L77

but this does not seem to apply to current SlingHttpServletRequest 
implementation or the current JCR resource implementation, they do not extend 
SlingAdaptable. if we add a scoping/caching support via @Model annotation we 
have to make sure that does not mix up with the SlingAdaptable caching 
implementation.

---

concerning the ticket in general: as already discussed "application" scope is 
dangerous, this should be OSGi services instead sling models.

in general i have a slight "tension" when comparing OSGi services and Sling 
models: from a certain toplevel perspective view both provide quite same 
("dependency injection in POJOs and some sort of lifecycle"), but do this with 
completely different set of annotations. this is puzzling for new developers. 
if would be nice if sling models would be osgi components with the additional 
sling models stuff attached. but the osgi scoped lifecycle support is not 
extensible to support things like "cache per adaptable" or "per session".

> 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
> Attachments: SLING-6785.diff
>
>
> 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)


[jira] [Commented] (SLING-6785) Add support for scoped lifecycle of sling models

2017-04-21 Thread Justin Edelson (JIRA)

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

Justin Edelson commented on SLING-6785:
---

[~jebailey] the cache is a WeakHashMap where the keys are the adaptable, so it 
is really the lifecycle of the adaptable. In the request case, the cache 
entries for that adaptable are cleared out by GC once the request object is 
garbage collected. In the resource case, the same thing would happen when the 
resource was GC'd.

> 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
> Attachments: SLING-6785.diff
>
>
> 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)


[jira] [Commented] (SLING-6785) Add support for scoped lifecycle of sling models

2017-04-21 Thread Jason E Bailey (JIRA)

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

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

[~justinedelson] Wouldn't placing this in the AdapterManager persist the 
caching of this object beyond a single request?

> 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
> Attachments: SLING-6785.diff
>
>
> 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)


[jira] [Commented] (SLING-6785) Add support for scoped lifecycle of sling models

2017-04-21 Thread Justin Edelson (JIRA)

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

Justin Edelson commented on SLING-6785:
---

[~jelger]

bq. Just to make sure, you also agree that we could cache a model across 
components with different resources?

Maybe :) it would be up to the creator of the Model/AdapterFactory.

The model would be cached against the adaptable. So if the adaptable is the 
request, then it is cacheable. If the adaptable is the resource, then it 
wouldn't be cached for different resources since the adaptable is the same.

And there are plenty of cases where the adaptable is the request and it 
*shouldn't* be cached, i.e. if the model uses request attributes. But again, 
the model creator would know best how to handle this.

> 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
> Attachments: SLING-6785.diff
>
>
> 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)


[jira] [Commented] (SLING-6785) Add support for scoped lifecycle of sling models

2017-04-21 Thread Christophe Jelger (JIRA)

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

Christophe Jelger commented on SLING-6785:
--

[~justinedelson] Just to make sure, you also agree that we could cache a model 
across components with different resources? Because I really see this very 
useful, for example in an HTL script we could then have 
{{sly-use.shared="MySharedModel" sly-use.notShared="MyResourceBasedModel"}}

For the name, maybe {{scope="shared"}} is even more clear, and better than 
{{shared=true}} to still have a {{String}}.

> 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)


[jira] [Commented] (SLING-6785) Add support for scoped lifecycle of sling models

2017-04-21 Thread Justin Edelson (JIRA)

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

Justin Edelson commented on SLING-6785:
---

[~jelger] the problem for me with {{scope="request"}} is that it doesn't make a 
lot of sense to use that for the case where the adaptable is a Resource.

Maybe "scope" is the wrong term. "cacheLifecycle"? "bindToLifecycle"?

or just "cache=true" ;)

> 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)


[jira] [Commented] (SLING-6785) Add support for scoped lifecycle of sling models

2017-04-21 Thread Christophe Jelger (JIRA)

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

Christophe Jelger commented on SLING-6785:
--

[~justinedelson] Actually {{scope="adaptable"}} seems like the current 
situation to me, the model is adapted from the adaptable, period. So I still 
prefer {{scope="request"}} to indicate the "temporal" aspect. But it should 
definitely be a {{String}} to support future values.

[~jebailey] You're right that it's potentially dangerous when adapting from 
{{resources}}, but as Justin wrote, it's up to the model creator to make sure 
that this is done in safe manner. I see many potential benefits for this 
feature: for example, you can have a component that renders a navigation menu 
based on the current page, and then have that {{NavigationModel}} be shared by 
other components on the page (for example in a footer with navigation links) 
without the need to re-instantiate anything.

> 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)


[jira] [Commented] (SLING-6785) Add support for scoped lifecycle of sling models

2017-04-21 Thread Justin Edelson (JIRA)

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

Justin Edelson commented on SLING-6785:
---

bq. Regarding your proposal, do you foresee that the scope could be something 
else than an adaptable?

No, but I think we should leave ourselves a path way to doing that.

The alternative is just {{@Model(..., scoped=true)}}, but there's no harm that 
I can see in having that be a {{String}} and thus providing a way to support 
different scopes in the future.

> 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)


[jira] [Commented] (SLING-6785) Add support for scoped lifecycle of sling models

2017-04-21 Thread Justin Edelson (JIRA)

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

Justin Edelson commented on SLING-6785:
---

[~jebailey] I see your concern, but wouldn't the model creator know whether or 
not that was a problem and thus *not* add this annotation attribute? The use 
case I was concerned with is when using the request attribute injector, but the 
solution is simple... if you expect to inject request attributes, don't use 
scoping.

> 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)


[jira] [Commented] (SLING-6785) Add support for scoped lifecycle of sling models

2017-04-21 Thread Christophe Jelger (JIRA)

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

Christophe Jelger commented on SLING-6785:
--

Just to make sure this is clear, I do not mean that {{scope="request"}} means 
that the adaptable is a request, here "request" is in the sense of an HTTP 
request "lifecycle", but the adaptable could also be a resource. So I mean 
{{scope}} in the sense of a lifecycle or duration, like in JEE.

Regarding your proposal, do you foresee that the scope could be something else 
than an adaptable?

PS: regarding {{session}} and {{application}} I knew that this would be 
controversial but decided to leave this anyway in the issue. ;-)

> 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)


[jira] [Commented] (SLING-6785) Add support for scoped lifecycle of sling models

2017-04-21 Thread Jason E Bailey (JIRA)

[ 
https://issues.apache.org/jira/browse/SLING-6785?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=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)


[jira] [Commented] (SLING-6785) Add support for scoped lifecycle of sling models

2017-04-21 Thread Justin Edelson (JIRA)

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

Justin Edelson commented on SLING-6785:
---

Leaving aside the {{session}} and {{application}} scopes, I think if we want to 
make this more generally applicable, we need to use something other than 
"request". How about {{@Model(..., scope="adaptable")}} to indicate that we are 
scoping to the actual adaptable.

> 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)