[
https://issues.apache.org/jira/browse/SLING-3715?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Stefan Seifert updated SLING-3715:
----------------------------------
Attachment: 140820_SLING-3715_sling-object-injector.patch
here is a proposal for better support for class-based injection of common used
sling objects (request, response, SlingScriptHelper, resource,
resourceResolver):
[^140820_SLING-3715_sling-object-injector.patch]
it's used class-based injection only making the given name or name of field
invalid - for those 5 objects it's normally explicit which object is meant. so
the correct object is injected irrelevant if you name your field
"resourceResolver" or "resourceresolver" or "resolver.". as a bonus its adds
nice support for constructor-based injection where the name of the parameter
cannot be detected automatically.
if you find it useful we can add it to the sling models implementation (and
remove the existing ResourceResolverInjector instead). if not i will add it to
our own projects/frameworks.
> Sling Models: Support for class-based dependency injection
> ----------------------------------------------------------
>
> Key: SLING-3715
> URL: https://issues.apache.org/jira/browse/SLING-3715
> Project: Sling
> Issue Type: Improvement
> Components: Extensions
> Reporter: Stefan Seifert
> Priority: Minor
> Labels: models
> Attachments: 140820_SLING-3715_sling-object-injector.patch
>
>
> Currently Sling Models dependency injection is primary based on parameter
> name-based injection, and not on class-based injection (the latter is more
> common in Spring and comparable frameworks).
> here is Justins opinion on this topic (from the mailing list) and why he
> prefers name-based injection:
> {quote}
> Hi Stefan,
> The big problem IMHO with injecting by class vs. name is that by class
> is too ambigious in many cases. For example, in AEM, it is relatively
> common to want to inject a Page object, but in fact there are two
> different page objects which come into play (currentPage and
> resourcePage) and getting the wrong one could be highly problematic.
> You are correct that things like the request and response could
> presumably be injected by class rather than by name, but the question
> then becomes how do we judge these cases? In my opinion, the bindings
> names are sensible. I personally don't find myself wanting to write
> this very often:
> {code:java}
> @Inject
> private SlingHttpServletRequest somenameOtherThanRequest;
> {code}
> \[...\]
> Regards,
> Justin
> {quote}
--
This message was sent by Atlassian JIRA
(v6.2#6252)