You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ju...@apache.org on 2014/01/31 05:14:35 UTC

svn commit: r1563050 - /sling/site/trunk/content/documentation/bundles/models.mdtext

Author: justin
Date: Fri Jan 31 04:14:34 2014
New Revision: 1563050

URL: http://svn.apache.org/r1563050
Log:
adding information on constructor injection and injector order

Modified:
    sling/site/trunk/content/documentation/bundles/models.mdtext

Modified: sling/site/trunk/content/documentation/bundles/models.mdtext
URL: http://svn.apache.org/viewvc/sling/site/trunk/content/documentation/bundles/models.mdtext?rev=1563050&r1=1563049&r2=1563050&view=diff
==============================================================================
--- sling/site/trunk/content/documentation/bundles/models.mdtext (original)
+++ sling/site/trunk/content/documentation/bundles/models.mdtext Fri Jan 31 04:14:34 2014
@@ -208,10 +208,28 @@ If the injected object does not match th
 
 When a resource is adapted to `MyModel`, a child resource named `image` is automatically adapted to an instance of `ImageModel`.
 
+Constructor injection is supported for the adaptable itself. For example:
+
+    ::java
+	@Model(adaptables=Resource.class)
+    public class MyModel {
+
+        public MyModel(Resource resource) {
+            this.resource = resource;
+        }
+
+        private final Resource resource;
+
+        @Inject
+        private String propertyName;
+    }
+
 # Custom Injectors
 
 To create a custom injector, simply implement the `org.apache.sling.models.spi.Injector` interface and register your implementation with the OSGi service registry. Please refer to the standard injectors in [Subversion](http://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/injectors/) for examples.
 
+Injectors are invoked in order of their service ranking, from lowest to highest. See the table below for the rankings of the standard injectors.
+
 # Annotation Reference
 `@Model`
 :   declares a model class or interface
@@ -242,10 +260,12 @@ To create a custom injector, simply impl
 
 # Available Injectors
 
-Title              |  Name (for `@Source`)   | Description	| Applicable To (including using `@Via`) | Notes
+Title              |  Name (for `@Source`)   | Service Ranking | Description	| Applicable To (including using `@Via`) | Notes
 -----------------  | ----------------------- | -------- | ------ | -----
-Value Map          | `valuemap`              |  Gets a property from a `ValueMap` | Any object which is or can be adapted to a `ValueMap`
-OSGI Services      | `osgi-services`           | Lookup services based on class name | Any object | Effectively ignores name.
-Script Bindings    | `script-bindings`          | Lookup objects in the script bindings object | A ServletRequest object which has the `Sling Bindings` attribute defined	
-Child Resources    | `child-resources`         | Gets a child resource by name | `Resource` objects
-Request Attributes | `request-attributes`      | Get a request attribute       | `ServletRequest` objects	
+Script Bindings    | `script-bindings`       | 1000   | Lookup objects in the script bindings object | A ServletRequest object which has the `Sling Bindings` attribute defined
+Value Map          | `valuemap`              | 2000 | Gets a property from a `ValueMap` | Any object which is or can be adapted to a `ValueMap`
+Child Resources    | `child-resources`       | 3000  | Gets a child resource by name | `Resource` objects
+Request Attributes | `request-attributes`    | 4000  | Get a request attribute       | `ServletRequest` objects	
+OSGI Services      | `osgi-services`         | 5000  | Lookup services based on class name | Any object | Effectively ignores name.
+	
+