You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Stefan Seifert (JIRA)" <ji...@apache.org> on 2014/06/30 22:26:25 UTC
[jira] [Created] (SLING-3718) Sling Models: Add self Injector for
supporting chains of object injecting dependencies from a common source
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/%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)