You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ferran Maylinch <fe...@gmail.com> on 2012/03/20 10:01:32 UTC

Why not setter injection or thread-safe field @Inject?

Hello,

Reading the documentation, I assume Tapestry does not perform setter
injection (like Spring). Also, I've read that @Inject directly into fields
is not thread-safe so constructor injection or build* methods are the
recommended ways.

I wonder why Tapestry does not allow setter injection and thread-safe
@Inject if build* methods are already thread-safe (aren't they?). Setter
injection would be something similar: Tapestry would instantiate the
service and set dependencies before letting anyone use the service (as I
presume it does with build* methods). Field @Inject would be something
similar too.

Thank you

Re: Why not setter injection or thread-safe field @Inject?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 20 Mar 2012 06:01:32 -0300, Ferran Maylinch  
<fe...@gmail.com> wrote:

> Hello,

Hi!

> is not thread-safe so constructor injection or build* methods are the
> recommended ways.
> I wonder why Tapestry does not allow setter injection and thread-safe
> @Inject if build* methods are already thread-safe (aren't they?).

You've already answered your own question one sentence before it:  
Tapestry-IoC recommends contructor injection. It has an additional  
advantage: your service classes work exactly the same way when you work  
with them without Tapestry-IoC. In other words, nobody felt the need to  
provide setter injection.

-- 
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


Re: Why not setter injection or thread-safe field @Inject?

Posted by Denis Stepanov <de...@gmail.com>.
Calling setAcessible on the same field from different threads is not thread-safe, but it's a special case, don't be affraid to use field injection.

Denis

Mar 20, 2012 v 1:49 PM, fmaylinch:

> 
> Denis Stepanov-2 wrote
>> 
>> Where did you read about fields injection not being thread safe? It's
>> definitely not true. Some developers like to use constructor injection
>> because of better testing etc. personally I'm using mostly field
>> injection.
>> 
> 
> Here: 
> http://tapestry.apache.org/defining-tapestry-ioc-services.html#DefiningTapestryIOCServices-FieldInjection
> Field Injection 
> 
> It says:
> 
> 
> 
>> Caution: injection via fields uses reflection to make the fields
>> accessible. In addition, it may not be as thread-safe as using the
>> constructor to assign to final fields.
>> 
> 
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Why-not-setter-injection-or-thread-safe-field-Inject-tp5579388p5579927.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Why not setter injection or thread-safe field @Inject?

Posted by fmaylinch <fe...@gmail.com>.
Denis Stepanov-2 wrote
> 
> Where did you read about fields injection not being thread safe? It's
> definitely not true. Some developers like to use constructor injection
> because of better testing etc. personally I'm using mostly field
> injection.
> 

Here: 
http://tapestry.apache.org/defining-tapestry-ioc-services.html#DefiningTapestryIOCServices-FieldInjection
Field Injection 

It says:



> Caution: injection via fields uses reflection to make the fields
> accessible. In addition, it may not be as thread-safe as using the
> constructor to assign to final fields.
> 


--
View this message in context: http://tapestry.1045711.n5.nabble.com/Why-not-setter-injection-or-thread-safe-field-Inject-tp5579388p5579927.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Why not setter injection or thread-safe field @Inject?

Posted by Denis Stepanov <de...@gmail.com>.
Where did you read about fields injection not being thread safe? It's definitely not true. Some developers like to use constructor injection because of better testing etc. personally I'm using mostly field injection.

Setter injection is just not implemented, IMHO IOC should support method injection when it's annotated with @Inject just like JSR-330 describes it.

Denis

Mar 20, 2012 v 10:01 AM, Ferran Maylinch:

> Hello,
> 
> Reading the documentation, I assume Tapestry does not perform setter
> injection (like Spring). Also, I've read that @Inject directly into fields
> is not thread-safe so constructor injection or build* methods are the
> recommended ways.
> 
> I wonder why Tapestry does not allow setter injection and thread-safe
> @Inject if build* methods are already thread-safe (aren't they?). Setter
> injection would be something similar: Tapestry would instantiate the
> service and set dependencies before letting anyone use the service (as I
> presume it does with build* methods). Field @Inject would be something
> similar too.
> 
> Thank you


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org