[prev in list] [next in list] [prev in thread] [next in thread]
List: tapestry-user
Subject: Re: Problem injecting a Logger
From: Howard Lewis Ship <hlship () gmail ! com>
Date: 2010-12-28 23:33:23
Message-ID: AANLkTi=rQsi7YQ40OLjB+ye30ch=4X2UQxfDqUTLem=c () mail ! gmail ! com
[Download RAW message or body]
You're seeing the evolution of the framework.
Originally, there was only constructor injection for services. This is
because we did not, originally, use a special class loader for service
implementations and we were trying to avoid reflection.
Components always used a special class loader, which allowed for proper
injection (including intercepting attempted updates to the fields, to make
the read-only).
Later (5.1 I believe) we started allowing injection into fields of service
implementation, using reflection.
However, there's an ambiguity. Normally, once Tapestry selects a
constructor, it provides an injection value for each parameter, based on
type (and other annotation).
Normally, a component parameter of type Logger is recognized, by type, as a
service resource (i.e., not another service, but a unique value constructed
just for this service). Adding the @Inject annotation tells Tapestry to
ignore it as a service resource and resolve it as an ordinary injection
(i.e., a service, or an object obtained from the MasterObjectProvider).
For fields, each field needs an @Inject annotation (Tapestry ignores most
fields and only performs injection on the ones that need it). But
that ambiguity ... @Inject should also work the same for a field as it does
for a parameter (meaning, resolve as a service, not a resource). The
solution was yet another annotation, @InjectResource, which is only for
fields, and indicates that Tapestry should perform a resource injection on
the field, as it would for a constructor parameter.
Confusing? Yes, just a touch. It's one of the reasons I prefer constructor
injection.
On Tue, Dec 28, 2010 at 3:15 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:
> On Tue, 28 Dec 2010 21:11:58 -0200, Josh Canfield <joshcanfield@gmail.com>
> wrote:
>
> Weird. Has that always been true?
>>
>
> No. I can't remember when, though.
>
>
> I'm also confused
>> why @Inject would work with Logger in a Component, but not in a service.
>>
>
> Injection of some object types are handled by class transformations, not
> IoC.
>
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Howard M. Lewis Ship
Creator of Apache Tapestry
The source for Tapestry training, mentoring and support. Contact me to learn
how I can get you up and productive in Tapestry fast!
(971) 678-5210
http://howardlewisship.com
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic