You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Alfonso Quiroga <al...@gmail.com> on 2009/11/21 15:56:02 UTC

injecting services outside default packages

Hi! I want to insert some service like this:
@Inject private MyService myService;
If I do it in default packages (base, pages, components) it just
works... but I have a class outside this packages and TapIOC does
nothing (myService is null). Some way to solution? thanks!!

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


Re: injecting services outside default packages

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Sat, 21 Nov 2009 14:18:20 -0200, Alfonso Quiroga  
<al...@gmail.com> escreveu:

> I think that's the problem, my bean is here
> /pages
> /components
> /myPackage/MyBean.java
>
> ..and the problem is that I instanciate ( new MyBean() ).

When you instantiate some object directly, Tapestry-IoC cannot do any  
injections on it.

> is a class I want to have in the session... how can I instanciate it
> with T5IoC? thanks in advance

As your MyBean isn't and shouldn't be a proper service, inject the  
ObjectLocator service and the use its autobuild(Class type) method to  
instantiate your class: MyBean bean =  
objectLocator.autobuild(MyBean.class);

Why would an object in a session have a reference to a service? That's  
something I don't recommend.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, 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: injecting services outside default packages

Posted by Alfonso Quiroga <al...@gmail.com>.
I think that's the problem, my bean is here
/pages
/components
/myPackage/MyBean.java

..and the problem is that I instanciate ( new MyBean() ). MyBean.java
is a class I want to have in the session... how can I instanciate it
with T5IoC? thanks in advance

On Sat, Nov 21, 2009 at 12:24 PM, Thiago H. de Paula Figueiredo
<th...@gmail.com> wrote:
> Em Sat, 21 Nov 2009 12:56:02 -0200, Alfonso Quiroga <al...@gmail.com>
> escreveu:
>
>> Hi! I want to insert some service like this:
>> @Inject private MyService myService;
>> If I do it in default packages (base, pages, components) it just
>> works... but I have a class outside this packages and TapIOC does
>> nothing (myService is null). Some way to solution? thanks!!
>
> It should work as long as both services (the one with the @Inject field and
> the injected one) are instantiated by Tapestry IoC.
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and
> instructor
> Owner, software architect and developer, 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
>
>

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


Re: injecting services outside default packages

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Sat, 21 Nov 2009 12:56:02 -0200, Alfonso Quiroga  
<al...@gmail.com> escreveu:

> Hi! I want to insert some service like this:
> @Inject private MyService myService;
> If I do it in default packages (base, pages, components) it just
> works... but I have a class outside this packages and TapIOC does
> nothing (myService is null). Some way to solution? thanks!!

It should work as long as both services (the one with the @Inject field  
and the injected one) are instantiated by Tapestry IoC.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, 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