You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Erik Fäßler <er...@uni-jena.de> on 2011/05/31 18:39:50 UTC

Stateful service

  Hey all,

I'm sure this question has been answered a lot - but I couldn't find an 
answer for so please excuse this :-)

I have a service which is filled with data at one class (some random 
Java class, no page). Then, in another class, I'd like to retrieve the 
service and get the data. I do it this way because quite a lot of 
objects are involved with the service and I wanted to take advantage by 
Tapestry's pooling so I wouldn't have to create all these objects again 
and again.

But when I try to re-take the service in the other class I get another 
instance, thus I don't have access to the data.

My questions:
Is there away around this? I could, for example, just pass a reference 
of this object from the first class to the second. Would this be bad 
style? Is there a mechanism for what I'd like to do I'm just not aware of?

Best regards,

     Erik

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


Re: Stateful service

Posted by Josh Canfield <jo...@gmail.com>.
> But before doing something unnecessary: I would need a separate instance of my service for each user session, holding information for this particular session. Would I get this when switching to the T5.2 IoC?

I haven't heard of anyone implementing a per-session service scope. In
T5 instead of having multiple instances of your service per-session
you'll either have a singleton or per-thread service with your session
state bean stored via the ApplicationStateManager.

Josh

On Tue, May 31, 2011 at 2:42 PM, Erik Fäßler <er...@uni-jena.de> wrote:
> Hey, thanks for your answer!
>>> .
>>
>> How is this second class getting the service object? If the service is singleton (this is the default scope in Tapestry-IoC), the same service instance is injected. Don't forget that both classes need to be Tapestry-IoC services for them to have service injection.
>>
> Hm, my application uses Chinellekit to employ Hivemind with Tapestry 5.2...this is because of legacy reasons. My services are currently defined in a hivemodule.xml, pooled and set- or constructor-injected. But my plan is to switch all my services to the Tapestry IoC container anyway. So perhaps I should just do this first and then see how the thing behaves.
>
> But before doing something unnecessary: I would need a separate instance of my service for each user session, holding information for this particular session. Would I get this when switching to the T5.2 IoC?
>
> Sorry for my newbie-answers, I'm not yet aware of the full changes of Tapestry since T4. But working on it...;-)
>
> Best,
>
> Erik
> ---------------------------------------------------------------------
> 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: Stateful service

Posted by Erik Fäßler <er...@uni-jena.de>.
Hey, thanks for your answer!
>> .
> 
> How is this second class getting the service object? If the service is singleton (this is the default scope in Tapestry-IoC), the same service instance is injected. Don't forget that both classes need to be Tapestry-IoC services for them to have service injection.
> 
Hm, my application uses Chinellekit to employ Hivemind with Tapestry 5.2...this is because of legacy reasons. My services are currently defined in a hivemodule.xml, pooled and set- or constructor-injected. But my plan is to switch all my services to the Tapestry IoC container anyway. So perhaps I should just do this first and then see how the thing behaves.

But before doing something unnecessary: I would need a separate instance of my service for each user session, holding information for this particular session. Would I get this when switching to the T5.2 IoC?

Sorry for my newbie-answers, I'm not yet aware of the full changes of Tapestry since T4. But working on it...;-)

Best,

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


Re: Stateful service

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 31 May 2011 13:39:50 -0300, Erik Fäßler  
<er...@uni-jena.de> wrote:

>   Hey all,

Hi!

> I have a service which is filled with data at one class (some random  
> Java class, no page). Then, in another class, I'd like to retrieve the  
> service and get the data. I do it this way because quite a lot of  
> objects are involved with the service and I wanted to take advantage by  
> Tapestry's pooling so I wouldn't have to create all these objects again  
> and again.

Tapestry-IoC doesn't pool service instances. Before 5.2, Tapestry (the web  
framework, not the IoC one) pooled pages instances, but 5.2 doesn't.

> But when I try to re-take the service in the other class I get another  
> instance, thus I don't have access to the data.

How is this second class getting the service object? If the service is  
singleton (this is the default scope in Tapestry-IoC), the same service  
instance is injected. Don't forget that both classes need to be  
Tapestry-IoC services for them to have service 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