Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-3715

Sling Models: Support for class-based dependency injection

    XMLWordPrintableJSON

Details

    Description

      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:

      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:

      @Inject
      private SlingHttpServletRequest somenameOtherThanRequest;
      

      [...]
      Regards,
      Justin

      Attachments

        Issue Links

          Activity

            People

              justinedelson Justin Edelson
              sseifert Stefan Seifert
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: