New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Architecture] Model classes should support adaptation from Resource #467
Comments
hi @HitmanInWis , thx for your feedback. The models of the Core Components are meant to be used to render within a page. We assume a page request context. We didn’t design them to be adapted from a Resource. There are a few objects that are only available within a page request context, e.g. |
I understand, but some of this stuff can be handled generically in a base model class if we need to. For example, we could define
A component is an entity that exists outside the context of a HTTP request, so limiting the sling models to only working within the context of a HTTP request feels like we've tightly bound two things that shouldnt be. I'm not advocating we take all request-related logic out of sling models, but I feel that the parts of a sling model that do not require a request should be able to work without it. |
I agree that this would be feasible but it requires some effort. Do you have a specific use case or a customer/project need that would benefit from it? Could you share more details? |
Here are some use cases where having sling models support
|
Also note https://issues.apache.org/jira/browse/SLING-8279 - if this were to be addressed, we could actually have models adapt primarily from a |
For the child resources injector I think it makes sense to extend that. I started a discussion in https://www.mail-archive.com/dev@sling.apache.org/msg83942.html. |
FWIW @adamcin and I have already coded up a new |
@HitmanInWis Thx for the list of use cases. Once Sling is extended to facilitate adaption from a Resource, you're welcome to submit a pull request to make the Core Components models adapt from a Resource. |
Sling already facilitates adaption from a Resource (i.e. |
@HitmanInWis yes sorry I got confused with the Sling issue posted above. If nothing in Sling stands in the way, you're welcome to submit a pull request to make the Core Components models adapt from a Resource. |
Feature Request
Looking through WCM Core components, I see that almost all of them are coded to support adaptation from only a
SlingHttpServletRequest.class
, and not aResource.class
. This means that in the context of an OSGi service that runs outside the context of a sling request (event listeners, scheduled jobs, data pollers, etc.), these model classes cannot be used.I understand that model classes often have some functionality that depends on a sling request, but often much of the functionality including reading properties from the JCR does not. As long as a model is coded to allow an injected request object to be optional, those models can still be very useful in back end OSGi code.
Can someone explain to me why we are limiting WCM Core components to only be used in the context of a web request? Or would people be open to the enhancement of allowing WCM Core models to be adapted from a straight
Resource
as well?The text was updated successfully, but these errors were encountered: