>> my current usecases are:
>> - having the ability to inject context objects like request in any sling
>model, regardless of the adaptable. this is e.g. importing when adapting from
>a resource, but in context of a request (SLING-4083)
>
>That should be possible to solve differently, such injection sounds like too
>much magic to me. Why can't sling models have a clear API that passes in such
>objects when they are created instead of going through a threadlocal?

sling models is based on a very simple API: adaptTo().

adaptTo passes in only the adaptable, and if this is not the request object 
there is no chance for the sling models implementation to get hold of it 
besides some "not-so-clean" way using a threadlocal.

but it's not always possible nor desired to just use the request as adaptable. 
e.g. if you handle multiple different resources inside your request and adapt 
them to a model and need access to the request there is no other way i can 
think of.


if fully agree that this way to access a request should not be the "standard 
way", and in most usecases there should be a better way (although not in the 
wcm.io configuration example because it as well relies on adaptTo(), but do not 
discuss this here in this thread further). SlingObjectInjectorRequestContext 
was only an name internal to the implementation of sling models.

stefan

Reply via email to