On Wed, Oct 22, 2014 at 5:44 PM, Alexander Klimetschek
<aklim...@adobe.com> wrote:
> On 22.10.2014, at 14:36, Justin Edelson <jus...@justinedelson.com> wrote:
>> To be clear, Sling Models was designed *not* to have an explicit API
>> and to be a way to implement of AdapterFactories. For version 1.2.0,
>> it does have an API, but this is essentially just a mirror of the
>> AdapterManager API plus some utility methods.
>
> On 22.10.2014, at 14:34, Stefan Seifert <sseif...@pro-vision.de> wrote:
>> 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.
>
> Maybe that's the problem and sling models should have a better way to be 
> created instead of piggy-backing on the magic adaptTo().

Except what Stefan is highlighting is actually a generalized problem
with the adapter subsystem and not at all specific to Sling Models.
His use case could just as easily be rephased as "I want to adapt an
instance of Foo and in my AdapterFactory get to Bar (which is not
navigable from Foo), but I don't want the caller to have to worry
about this.", the outcome would be the same.

The only distinction is that these particular AdapterFactory
implementations are generated by Sling Models. This, however, is a
distinction without difference.

Personally, I don't quite see the use case -- if your AdapterFactory
(whether it is generated by Sling Models or hand-coded) needs
request-based context, the adaptable is the request.

>
> For JSPs: a taglib. For Java services: a service with methods like 
> getModel(type, request) and getModel(type, resolver) etc. Imagine there is no 
> ThreadLocal and adaptTo() available, how would you solve it in the most 
> convenient fashion?

Such an API now exists, but I don't see how it changes this
discussion. The only way I see this API helping the use case is to
pass some kind of context object into the getModel(), e.g.
getModel(type, resource, Collections.singletonMap("request",
request)). Is this along the lines of what you are suggesting? And
again, if the caller knows they need to pass in the request, then the
adaptable should be the request.

Regards,
Justin
>
> Cheers,
> Alex

Reply via email to