You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Justin Edelson (JIRA)" <ji...@apache.org> on 2014/08/20 00:55:20 UTC
[jira] [Resolved] (SLING-3718) Sling Models: Add self Injector for
supporting chains of object injecting dependencies from a common source
[ https://issues.apache.org/jira/browse/SLING-3718?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Justin Edelson resolved SLING-3718.
-----------------------------------
Resolution: Fixed
Resolved in r1619007. See SLING-3716 for more details.
> Sling Models: Add self Injector for supporting chains of object injecting dependencies from a common source
> -----------------------------------------------------------------------------------------------------------
>
> Key: SLING-3718
> URL: https://issues.apache.org/jira/browse/SLING-3718
> Project: Sling
> Issue Type: Improvement
> Components: Extensions
> Reporter: Stefan Seifert
> Assignee: Justin Edelson
> Priority: Minor
> Fix For: Sling Models Implementation 1.0.8, Sling Models API 1.0.4
>
> Attachments: 140701_SLING-3716_slingmodes_constructorinjection_SLING-3718_selfinjector.patch
>
>
> as discussed in my post on the sling mailing list
> http://mail-archives.apache.org/mod_mbox/sling-dev/201406.mbox/%3C580AFA6C6DAB8A4196956DA5EE17C8CA8F7619E558@feanor.pro-vision.de%3E
> it would be very helpful to have a "self-adapting" injector to support chains of objects (e.g. controller classes depending on business classes) that all can adapt themselves from a common source, e.g. a SlingHttpServletRequest or a ResourceResolver.
> souch an injector can be simple like this:
> {code:java}
> @Component
> @Service
> @Property(name = Constants.SERVICE_RANKING, intValue = 50)
> public class SelfAdaptInjector implements Injector {
> public String getName() {
> return "selfadapt";
> }
> public Object getValue(Object pAdaptable, String pName, Type pType, AnnotatedElement pElement,
> DisposalCallbackRegistry pCallbackRegistry) {
> if (!(pType instanceof Class)) {
> return null;
> }
> if (!(pAdaptable instanceof Adaptable)) {
> return null;
> }
> return ((Adaptable)pAdaptable).adaptTo((Class<?>)pType);
> }
> }
> {code}
> comment from Justin on this in the mailing list:
> {quote}
> The self injector is interesting. I held off on that initially because
> it seems too easy to create a circular injection. Any thoughts on how
> that can be avoided?
> \[...\]
> Regards,
> Justin
> {quote}
--
This message was sent by Atlassian JIRA
(v6.2#6252)