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/07/01 11:36:24 UTC
[jira] [Updated] (SLING-3716) Sling Models: Add support for
constructor dependency injection
[ https://issues.apache.org/jira/browse/SLING-3716?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Stefan Seifert updated SLING-3716:
----------------------------------
Attachment: 140701_SLING-3716_slingmodes_constructorinjection.patch
attached is a patch for adding constructor injection support to sling models including unit tests.
some remarks:
* due to missing support in java reflection it is not possible to get the name of a constructor parameter without resorting external tools like objectweb ASM. i did not wanted to introduce this only for this usecase. So if an injector is used that depends on name-based injection a @Named parameter or equivalent injector-specific annotation with name attribute is mandatory. the existing injector implementations where extended to ensure that they can cope with a null name attribute and unit tests were added for this case.
* by default only constructors which are annotated with @Inject are supported for constructor injection. to keep compatibility with previous sling implementation releases the special case with one-parameter constructor matching the adaptable is still supported.
* to make the injection of the adaptable itself more generic and support it in multiple parameter constructors i added a new "SelfInjector". this is supported for field injection as well.
* currently there is no SelfInjector-specific annotation, the matching is class based. we can easily add one, this touches the topics discussed in SLING-3715 and SLING-3718 as well.
* integration test added as well
> Sling Models: Add support for constructor dependency injection
> --------------------------------------------------------------
>
> Key: SLING-3716
> URL: https://issues.apache.org/jira/browse/SLING-3716
> Project: Sling
> Issue Type: Improvement
> Components: Extensions
> Reporter: Stefan Seifert
> Priority: Minor
> Attachments: 140701_SLING-3716_slingmodes_constructorinjection.patch
>
>
> Currently, Sling Models only supports dependency injection for fields (or interface getter methods), but not for constructor arguments. This ticket is for discussing what this constructor dependency injection should support, and perhaps finally provide a patch to implement it.
> This is somewhat related to SLING-3715 for class-based dependency injection, because this would come in especially handy for constructor injection.
--
This message was sent by Atlassian JIRA
(v6.2#6252)