Hi,
I am a little bit worried that model classes which leverage the Sling Models 
annotations might be slow and break fast. 

If you use the annotation @Inject without @Source all injectors are asked until 
one returns a value.
Since almost all injectors depend on the fieldname and cover the same 
namespace, models can break very easily.
Let me give three examples for broken models:

a) If I use in my model
@Inject
String myattribute;
which used to be resolved by the ValueMap injector and I just introduced a new 
Scripting variable with the name “myattribute” 
(https://cwiki.apache.org/confluence/display/SLING/Adding+New+Scripting+Variables),
 my model would no longer work.
b) The same would apply, if I have a Sling resource with a value named 
“service” which used to be (by coincidence) also the field name of my injected 
OSGi service in the model.
c) The same for a new request attribute, whose name conflicts with the field 
name of my injected OSGi service in the model

Regarding the performance, I fear that the lookup in the value map from the 
second injector might take some time (since JCR access is necessary in most 
cases to do that). For example if I have a model class only relying on OSGi 
services a lot of time would be wasted by asking other injectors.

To summarize: Isn’t it always advisable to use the @Source annotation to 
prevent those kind of name clashes and performance issues? Shouldn’t that be 
explicitly stated in the documentation?
What is your opinion on that?

What about making the @Source mandatory for all injectors but the ValueMap 
injector?
Thanks,
Konrad



Reply via email to