joerghoh commented on code in PR #106:
URL: https://github.com/apache/sling-site/pull/106#discussion_r1062398340
##########
src/main/jbake/content/documentation/bundles/models.md:
##########
@@ -179,92 +150,121 @@ Since Sling Models 1.2.0 there is another way of
instantiating models. The OSGi
// See the javadoc of the ModelFactory for which Exception can be
expected here
}
-In addition `ModelFactory` provides methods for checking whether a given class
is a model at all (having the model annotation) or whether a class can be
adapted from a given adaptable.
+In addition `ModelFactory` provides methods for checking whether a given class
is a model at all (having the model annotation) or whether a class can be
adapted from a given adaptable.
## Usage in HTL
-[Sling Models Use
Provider](/documentation/bundles/scripting/scripting-htl.html#java-use-provider-1)
(internally uses the `ModelFactory` from above).
+Please see [Sling Models Use
Provider](/documentation/bundles/scripting/scripting-htl.html#java-use-provider-1);
internally it uses the `ModelFactory` from above.
-# Other Options
-## Names
-If the field or method name doesn't exactly match the property name, `@Named`
can be used:
- ::java
- @Model(adaptables=Resource.class)
- public class MyModel {
-
- @Inject @Named("secondPropertyName")
- private String otherName;
- }
-
+# Available injectors
+
+In the above cases just the `@ValueMapValue` annotation was used, but there
other available injectors. For each injector there is a specialized annotation
available. For the optional parameters see the next section.
+
+
+Injector Name | Annotation | Supported Optional Elements |
Description | Array Support | Parametrized Type Support
Review Comment:
I added more rows to the table and included the name and the column
"Applicable to".
##########
src/main/jbake/content/documentation/bundles/models.md:
##########
@@ -660,86 +612,78 @@ If you want to generate a bundle header compliant with
Sling Models < 1.3.4 (i.e
</instructions>
</configuration>
-# Caching
-By default, Sling Models do not do any caching of the adaptation result and
every request for a model class will
-result in a new instance of the model class. However, there are two notable
cases when the adaptation result can be cached. The first case is when the
adaptable extends the `SlingAdaptable` base class. Most significantly, this is
the case for many `Resource` adaptables as `AbstractResource` extends
`SlingAdaptable`. `SlingAdaptable` implements a caching mechanism such that
multiple invocations of `adaptTo()` will return the same object. For example:
- ::java
- // assume that resource is an instance of some subclass of AbstractResource
- ModelClass object1 = resource.adaptTo(ModelClass.class); // creates new
instance of ModelClass
- ModelClass object2 = resource.adaptTo(ModelClass.class); // SlingAdaptable
returns the cached instance
- assert object1 == object2;
-While this is true for `AbstractResource` subclasses, it is notably **not**
the case for `SlingHttpServletRequest` as this class does not extend
`SlingAdaptable`. So:
- ::java
- // assume that request is some SlingHttpServletRequest object
- ModelClass object1 = request.adaptTo(ModelClass.class); // creates new
instance of ModelClass
- ModelClass object2 = request.adaptTo(ModelClass.class); // creates another
new instance of ModelClass
- assert object1 != object2;
+# Discouraged annotations
-Since API version 1.3.4, Sling Models *can* cache an adaptation result,
regardless of the adaptable by specifying `cache = true` on the `@Model`
annotation.
+In earlier versions of Sling Models the use of the annotation `@Inject` was
suggested and documented; but over time it turned out that it had 2 major
issues:
+* This injection iterated through all available injectors and injected the
first non-null value provided by an injector. This lead to unpredictable
behavior, although the order is well-defined. The addition of the `@Source`
annotation did not really help.
+* This iteration turned out to the performance bottleneck, especially if
(optional) injections were not succesful, and then all other injectors have to
be tried.
Review Comment:
+1
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]