Hi Dan,

On Thu, Dec 19, 2013 at 12:37 PM, Daniel Klco <[email protected]> wrote:
> Justin,
>
> This seems like a really nice addition.  I was working on something
> similar using Java's Dynamic Proxy to allow injection from the
> repository.  The model is slightly different where instead of
> annotating member variables, you annotate methods on an interface.
> http://svn.apache.org/repos/asf/sling/whiteboard/dklco/dynamic-proxy/

Yes - proxy based injection (of methods) works too. Most of the tests
are written with classes, but there is one or two with interfaces. The
SPI handles both cases.

>
> Overall, I'd actually say I like the approach you've defined.  A
> couple thoughts though:
>
> - Would it make sense to separate the property/service injection
> annotations to make it more clear what's being injected?

I don't think so - as a model developer, I shouldn't necessarily care
where my injections are coming from, just that they are being
injected.

> - How about adding support for the naming as variables in the Inject
> annotation instead of a separate annotation?  This would also go for
> some of the other annotations.  I think from a developer's perspective
> it makes more sense to configure an annotation than have to look up a
> bunch of different unconnected annotations,

As I wrote, one of the design goals is to use standard annotations.
@Inject and @Named are common annotations defined in the JDK.

> - Do the filters just work on service injection?

Correct, although there's no reason a different Injector couldn't use them.

> - So this one confuses me a little:
>
>  @Inject
>     @Named("log")
>     private Logger logger;
>
> Is the @Named being used for the page / request attributes?

Yes - in this case, "log" is the name of the SlingBindings attribute.

> How can
> one tell from where the injectable object will be loaded?

You can't :)

> Would there
> be any value/reason to being able to specify?

I don't think so, but I'm curious for others opinions. As someone who
builds a model class, why should it matter? I just say "I want a
String instance named 'firstProperty'" and it "magically" appears. Too
magical?

Justin

>
> Very cool though over all!
>
> -Dan
>
> On Thu, Dec 19, 2013 at 12:21 PM, Konrad Windszus <[email protected]> wrote:
>>
>> HI Justin,
>> thank a lot for that. I am assuming a lot of developers were waiting for 
>> just that. Could you extend the wiki page with an example on how the model 
>> bean should then be used from within the view (i.e. the JSP) and also some 
>> words about the scope of one instance?
>> One very good addition to the annotations would probably be a default value 
>> in case there is nothing reasonable to be injected (very useful for resource 
>> values which are not yet set).
>> Thanks,
>> Konrad
>>
>> Am 19.12.2013 um 18:07 schrieb Justin Edelson <[email protected]>:
>>
>> > Hi,
>> > I've published a page to the wiki about a concept I've been working on
>> > to consolidate the various appproaches I have seen in the wild to
>> > model object creation. I'm calling this YAMF for now, although ideally
>> > we'll just call it Sling Models :)
>> >
>> > Without repeating the whole contents of the wiki page, at a high
>> > level, this is a purely annotation driven approach supporting both
>> > classes and interfaces. Your model class simply needs to declare from
>> > which other classes it can be adapted:
>> >
>> > @Model(adaptables=Resource.class)
>> >
>> > And then annotate the fields (for classes) and methods (for
>> > interfaces) which need injection:
>> >
>> > @Inject
>> > private String propertyName;
>> >
>> > You can inject properties, OSGi services, request attributes, and
>> > entries from SlingBindings.
>> >
>> > New injector types can be created through an SPI.
>> >
>> > Additional annotations are supported for special cases:
>> >
>> > @Optional - mark a field/method as optional.
>> > @Filter - provide a filter (i.e. for OSGi services)
>> > @Named - specify a name (other than the default field/method name) to
>> > use for the inejction lookup.
>> >
>> > More detail can be found here:
>> > https://cwiki.apache.org/confluence/display/SLING/YAMF+-+Yet+Another+Model+Factory
>> >
>> > The working code is up in my whiteboard:
>> > https://svn.apache.org/repos/asf/sling/whiteboard/justin/yamf/
>> >
>> > Look forward to your feedback.
>> >
>> > Regards,
>> > Justin
>>

Reply via email to