You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Dmitriy Vsekhvalnov <dv...@gmail.com> on 2011/06/07 15:47:23 UTC

Tapestry IoC: Bean Scope

Hi all,

   is it possible to have services bound with Bean scope? I'm using Quartz
scheduler and my jobs are actually services bound in AppModule with all
dependency injection and so on.


  But i want different instances of jobs. So every time i call

     ServiceResources:getService(..., Job.class)

i want new instance back.

I remember it was not possible to implement with Hivemind, how about
Tapestry-IOC?

Thanks.

Re: Tapestry IoC: Bean Scope

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 07 Jun 2011 14:47:10 -0300, Dmitriy Vsekhvalnov  
<dv...@gmail.com> wrote:

> did i get you right, that i can simply inject ObjectLocator service to my
> Quartz JobFactory and instantiate jobs via autobuild()
> I mean sources saying all dependencies will be injected.

Yes. JavaDoc: Autobuilds a class by finding the public constructor with  
the most parameters. Services and resources will be injected into the  
parameters of the constructor.

-- 
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: Tapestry IoC: Bean Scope

Posted by Dmitriy Vsekhvalnov <dv...@gmail.com>.
did i get you right, that i can simply inject ObjectLocator service to my
Quartz JobFactory and instantiate jobs via autobuild()

I mean sources saying all dependencies will be injected.



On Tue, Jun 7, 2011 at 8:20 PM, Howard Lewis Ship <hl...@gmail.com> wrote:

> Unfortunately, Tapestry is not Spring :-)  The proxy you get back from
> a direct or indrect call to getService() is always global, though in
> the case of the perthread scope, that core service implementation is
> ... another proxy that manages and delegates to the per-thread
> instance.
>
> I think you need to use an explicit factory if you want to control
> when new instances are created. In fact, for ordinary beans, you can
> get the BeanModelSource, get a BeanModel for a class, and use its
> newInstance() method.
>
> However, that's roundabout, because newInstance() gets the
> ObjectLocator (which can be injected into any service) and invokes
> autobuild() on it ... so it's a very generic factory.
>
> On Tue, Jun 7, 2011 at 8:52 AM, Dmitriy Vsekhvalnov
> <dv...@gmail.com> wrote:
> > i was hoping someone already did it :)
> >
> > Last time i was trying to do it with Hivemind, proxy created a new
> instance
> > every method call, and this is not what i want. I mostly likely want
> > no-proxy, but just new instance.
> >
> > On Tue, Jun 7, 2011 at 6:32 PM, Thiago H. de Paula Figueiredo <
> > thiagohp@gmail.com> wrote:
> >
> >> On Tue, 07 Jun 2011 10:47:23 -0300, Dmitriy Vsekhvalnov <
> >> dvsekhvalnov@gmail.com> wrote:
> >>
> >>  Hi all,
> >>>
> >>
> >> Hi!
> >>
> >>
> >>    is it possible to have services bound with Bean scope? I'm using
> Quartz
> >>> scheduler and my jobs are actually services bound in AppModule with all
> >>> dependency injection and so on.
> >>>  But i want different instances of jobs. So every time i call
> >>>     ServiceResources:getService(..., Job.class)
> >>> i want new instance back.
> >>>
> >>
> >> Is what do you want the same as the prototype scope in Spring?
> >>
> >>
> >>  I remember it was not possible to implement with Hivemind, how about
> >>> Tapestry-IOC?
> >>>
> >>
> >> Tapestry-IoC provides singleton and per-thread scopes out of the box,
> but
> >> you can add your own ones. Implement ServiceLifecycle2 and contribute it
> to
> >> the ServiceLifecycleSource service. Take a look at the
> >> PerThreadServiceLifecycle source for an example.
> >>
> >> --
> >> 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
> >>
> >
>
>
>
> --
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Tapestry IoC: Bean Scope

Posted by Howard Lewis Ship <hl...@gmail.com>.
Unfortunately, Tapestry is not Spring :-)  The proxy you get back from
a direct or indrect call to getService() is always global, though in
the case of the perthread scope, that core service implementation is
... another proxy that manages and delegates to the per-thread
instance.

I think you need to use an explicit factory if you want to control
when new instances are created. In fact, for ordinary beans, you can
get the BeanModelSource, get a BeanModel for a class, and use its
newInstance() method.

However, that's roundabout, because newInstance() gets the
ObjectLocator (which can be injected into any service) and invokes
autobuild() on it ... so it's a very generic factory.

On Tue, Jun 7, 2011 at 8:52 AM, Dmitriy Vsekhvalnov
<dv...@gmail.com> wrote:
> i was hoping someone already did it :)
>
> Last time i was trying to do it with Hivemind, proxy created a new instance
> every method call, and this is not what i want. I mostly likely want
> no-proxy, but just new instance.
>
> On Tue, Jun 7, 2011 at 6:32 PM, Thiago H. de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
>
>> On Tue, 07 Jun 2011 10:47:23 -0300, Dmitriy Vsekhvalnov <
>> dvsekhvalnov@gmail.com> wrote:
>>
>>  Hi all,
>>>
>>
>> Hi!
>>
>>
>>    is it possible to have services bound with Bean scope? I'm using Quartz
>>> scheduler and my jobs are actually services bound in AppModule with all
>>> dependency injection and so on.
>>>  But i want different instances of jobs. So every time i call
>>>     ServiceResources:getService(..., Job.class)
>>> i want new instance back.
>>>
>>
>> Is what do you want the same as the prototype scope in Spring?
>>
>>
>>  I remember it was not possible to implement with Hivemind, how about
>>> Tapestry-IOC?
>>>
>>
>> Tapestry-IoC provides singleton and per-thread scopes out of the box, but
>> you can add your own ones. Implement ServiceLifecycle2 and contribute it to
>> the ServiceLifecycleSource service. Take a look at the
>> PerThreadServiceLifecycle source for an example.
>>
>> --
>> 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
>>
>



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

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


Re: Tapestry IoC: Bean Scope

Posted by Dmitriy Vsekhvalnov <dv...@gmail.com>.
i was hoping someone already did it :)

Last time i was trying to do it with Hivemind, proxy created a new instance
every method call, and this is not what i want. I mostly likely want
no-proxy, but just new instance.

On Tue, Jun 7, 2011 at 6:32 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Tue, 07 Jun 2011 10:47:23 -0300, Dmitriy Vsekhvalnov <
> dvsekhvalnov@gmail.com> wrote:
>
>  Hi all,
>>
>
> Hi!
>
>
>    is it possible to have services bound with Bean scope? I'm using Quartz
>> scheduler and my jobs are actually services bound in AppModule with all
>> dependency injection and so on.
>>  But i want different instances of jobs. So every time i call
>>     ServiceResources:getService(..., Job.class)
>> i want new instance back.
>>
>
> Is what do you want the same as the prototype scope in Spring?
>
>
>  I remember it was not possible to implement with Hivemind, how about
>> Tapestry-IOC?
>>
>
> Tapestry-IoC provides singleton and per-thread scopes out of the box, but
> you can add your own ones. Implement ServiceLifecycle2 and contribute it to
> the ServiceLifecycleSource service. Take a look at the
> PerThreadServiceLifecycle source for an example.
>
> --
> 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
>

Re: Tapestry IoC: Bean Scope

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 07 Jun 2011 10:47:23 -0300, Dmitriy Vsekhvalnov  
<dv...@gmail.com> wrote:

> Hi all,

Hi!

>    is it possible to have services bound with Bean scope? I'm using  
> Quartz scheduler and my jobs are actually services bound in AppModule  
> with all
> dependency injection and so on.
>   But i want different instances of jobs. So every time i call
>      ServiceResources:getService(..., Job.class)
> i want new instance back.

Is what do you want the same as the prototype scope in Spring?

> I remember it was not possible to implement with Hivemind, how about
> Tapestry-IOC?

Tapestry-IoC provides singleton and per-thread scopes out of the box, but  
you can add your own ones. Implement ServiceLifecycle2 and contribute it  
to the ServiceLifecycleSource service. Take a look at the  
PerThreadServiceLifecycle source for an example.

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