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:38:24 UTC
[jira] [Commented] (SLING-3715) Sling Models: Support for
class-based dependency injection
[ https://issues.apache.org/jira/browse/SLING-3715?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14048121#comment-14048121 ]
Stefan Seifert commented on SLING-3715:
---------------------------------------
well, it is a bit a questions of taste whether one prefers name-base injection or class-based injection.
in our projects we often have a naming convention to prefix member variables with a "m" (a remnant of of a hungarian naming conventions), which would completely break the name-based injection. and name-based injection can be fragile - i someone refactors a class and changes the (private) property name this can break the injection silently.
and we have not so much cases where there are two candidates for injecting to the same type - currentPage and resourcePage is the primary one you mentioned. in this case the "current" page would be the preferred candidate. if the "resourcePage" is requested, an additional @Named annotation could be used to make it explicit.
in most other cases - and e.g. in Spring its the common practice - class-based injection would be very helpful.
finally i think we should support both injection patterns - and let the user of the Sling Models framework or his development team decide which fits best into their best practices.
> 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
>
> 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)