Stefan Seifert created SLING-3718: ------------------------------------- Summary: 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 Priority: Minor
as discussed in my post on the sling mailing list http://mail-archives.apache.org/mod_mbox/sling-dev/201406.mbox/%3c580afa6c6dab8a4196956da5ee17c8ca8f7619e...@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)