Hi,
Shouldn’t we instead just more prominently promote injector-specific 
annotations 
(https://sling.apache.org/documentation/bundles/models.html#injector-specific-annotations
 
<https://sling.apache.org/documentation/bundles/models.html#injector-specific-annotations>)?
IMHO this should be fixed in the model and we shouldn’t try to be smarter with 
generic injections.

Konrad

> On 22. Jun 2022, at 13:43, Jörg Hoh <[email protected]> wrote:
> 
> Hi,
> 
> While investigating some weirdness in custom Sling Model Injectors I came
> across, that a SlingModel triggerd the invocation of the prepare() method
> of a totally unrelated Injector, which implements the ValuePreparer
> interface.
> 
> I found that if no injector is given in the annotation [1] all available
> injectors are taken [2], iterated and the ValuePreparer invoked (if it's
> implemented by the Injector).
> 
> That means that in case no specific injector is given, all injectors are
> tried, which can be costly in terms of time. What I miss (and what I think
> should be possible) is to reduce this list based on the type information.
> Because it does not make sense to query an Injector which can only return a
> String if an injection for the type SlingHttpServletRequest should be done.
> Would such an optimization be possible?
> 
> I don't have benchmark data yet how much time is spent in the process of
> injecting all required fields, but before I invest more time here, I wanted
> to understand if this is feasible at all.
> 
> Thanks,
> Jörg
> 
> 
> [1]
> https://github.com/apache/sling-org-apache-sling-models-impl/blob/ed1bd8d8a2fc01e13a10ba1c06122530c4d590b1/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java#L574
> 
> [2]
> https://github.com/apache/sling-org-apache-sling-models-impl/blob/ed1bd8d8a2fc01e13a10ba1c06122530c4d590b1/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java#L570
> 
> 
> 
> 
> -- 
> Cheers,
> Jörg Hoh,
> 
> https://cqdump.joerghoh.de
> Twitter: @joerghoh

Reply via email to