You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Andrey Larionov <an...@gmail.com> on 2009/09/08 16:01:58 UTC

How to create analog of Spring FactoryBean?

I want to remove a spring part from my project if possible. But i need
analog of spring FactoryBean. Read documentation but dosnt found any
point. I think solution is near of ObjectLocator or ObjectProvider,
but have no idea how to start. Anybody solve this problem?

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


Re: How to create analog of Spring FactoryBean?

Posted by Paul Field <pa...@db.com>.
> Peter Niederwieser <pn...@gmail.com> 
> I'd be interested to see a ServiceLifecycle implementation for prototype
> scope.

Kristian Marinkovic <kr...@porsche.co.at> wrote on 
16/09/2009 11:39:16:
> it is doable.... 
> 
> create a  - let's say - a factory service with a Bean getBean() method.
> then create a service for the Bean interface by using the 
> PropertyShadowBuilder
...
> when you
> access the bean, the factory.getBean() method will be called. and if you 

> always create a new bean you have what you need.

But bear in mind that you will get a new bean for *every method call* - 
which is probably not what you want. The thing about prototype beans in 
Spring is that you get a new instance when you request the bean from the 
container and after that it remains the same instance.

I think the only way to do it, is to expose the factory as the service, as 
I described here:
http://www.nabble.com/Re%3A-How-to-create-analog-of-Spring-FactoryBean--p25349917.html

The main downside I found is that you can't use the IOC container to 
proxy/decorate/advise the created instance.

- Paul







---

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.

Re: How to create analog of Spring FactoryBean?

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
hi peter,

it is doable.... 

create a  - let's say - a factory service with a Bean getBean() method.
then create a service for the Bean interface by using the 
PropertyShadowBuilder
service. then you'll be able to inject the Bean whereever you need it. 
when you
access the bean, the factory.getBean() method will be called. and if you 
always
create a new bean you have what you need.

g,
kris




Peter Niederwieser <pn...@gmail.com> 
15.09.2009 05:50
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
users@tapestry.apache.org
Kopie

Thema
Re: How to create analog of Spring FactoryBean?








I'd be interested to see a ServiceLifecycle implementation for prototype
scope. I recently tried to come up with one, but it didn't seem to be
doable.

Cheers,
Peter


Thiago H. de Paula Figueiredo wrote:
> 
> Then you can create a new Tapestry-IoC scope (ServiceLifecycle 
> implementation) that creates a new object everytime an injection is 
made.
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-create-analog-of-Spring-FactoryBean--tp25346888p25447319.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: How to create analog of Spring FactoryBean?

Posted by Peter Niederwieser <pn...@gmail.com>.
I'd be interested to see a ServiceLifecycle implementation for prototype
scope. I recently tried to come up with one, but it didn't seem to be
doable.

Cheers,
Peter


Thiago H. de Paula Figueiredo wrote:
> 
> Then you can create a new Tapestry-IoC scope (ServiceLifecycle  
> implementation) that creates a new object everytime an injection is made.
> 

-- 
View this message in context: http://www.nabble.com/How-to-create-analog-of-Spring-FactoryBean--tp25346888p25447319.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: How to create analog of Spring FactoryBean?

Posted by Andrey Larionov <an...@gmail.com>.
Also interesting, is in Tapestry dispose mechanism like in spring?
(Implementing DisposableBean)

On Wed, Sep 9, 2009 at 09:06, Andrey Larionov<an...@gmail.com> wrote:
> thanks paul.
>
> On Tue, Sep 8, 2009 at 20:46, Paul Field<pa...@db.com> wrote:
>> Hi Andrey,
>>
>> "Thiago H. de Paula Figueiredo" <th...@gmail.com> wrote on 08/09/2009
>> 15:51:14:
>>
>>> Em Tue, 08 Sep 2009 11:27:06 -0300, Andrey Larionov
>> <an...@gmail.com>
>>> escreveu:
>>>
>>> > No, FactoryBean can create new instance on every call of getObject.
>>>
>>> Then you can create a new Tapestry-IoC scope (ServiceLifecycle
>>> implementation) that creates a new object everytime an injection is
>> made.
>>
>> Do  you mean you want a service that acts like a "prototype" bean in
>> Spring? You could create a new scope as Thiago suggests but you are likely
>> to end up with a service that creates a new underlying object for every
>> method call - and that probably isn't what you want.
>>
>> I suggest simply creating a service that is a Factory; maybe something
>> like this:
>>
>> public final class AppModule {
>>    public static void bind(ServiceBinder binder) {
>>        binder.bind(ConnectionFactory.class, ConnectionFactoryWithPool.
>> class);
>>    }
>> }
>>
>>
>> public interface ConnectionFactory {
>>    Connection createConnection();
>> }
>>
>>
>> public class ConnectionFactoryWithPool implements ConnectionFactory {
>>
>>    ....
>>
>>    public Conection createConnection() {
>>        return pool.getConnection();
>>    }
>> }
>>
>>
>> public class MyPage {
>>    @Inject
>>    private ConnectionFactory connectionFactory;
>>
>>    public void myAction() {
>>        Connection connection = connectionFactory.createConnection();
>>        try {
>>            ...
>>        } finally {
>>            connection.close();
>>        }
>>    }
>> }
>>
>>
>> - Paul
>>
>>
>> ---
>>
>> This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
>>
>> Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.
>

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


Re: How to create analog of Spring FactoryBean?

Posted by Andrey Larionov <an...@gmail.com>.
thanks paul.

On Tue, Sep 8, 2009 at 20:46, Paul Field<pa...@db.com> wrote:
> Hi Andrey,
>
> "Thiago H. de Paula Figueiredo" <th...@gmail.com> wrote on 08/09/2009
> 15:51:14:
>
>> Em Tue, 08 Sep 2009 11:27:06 -0300, Andrey Larionov
> <an...@gmail.com>
>> escreveu:
>>
>> > No, FactoryBean can create new instance on every call of getObject.
>>
>> Then you can create a new Tapestry-IoC scope (ServiceLifecycle
>> implementation) that creates a new object everytime an injection is
> made.
>
> Do  you mean you want a service that acts like a "prototype" bean in
> Spring? You could create a new scope as Thiago suggests but you are likely
> to end up with a service that creates a new underlying object for every
> method call - and that probably isn't what you want.
>
> I suggest simply creating a service that is a Factory; maybe something
> like this:
>
> public final class AppModule {
>    public static void bind(ServiceBinder binder) {
>        binder.bind(ConnectionFactory.class, ConnectionFactoryWithPool.
> class);
>    }
> }
>
>
> public interface ConnectionFactory {
>    Connection createConnection();
> }
>
>
> public class ConnectionFactoryWithPool implements ConnectionFactory {
>
>    ....
>
>    public Conection createConnection() {
>        return pool.getConnection();
>    }
> }
>
>
> public class MyPage {
>    @Inject
>    private ConnectionFactory connectionFactory;
>
>    public void myAction() {
>        Connection connection = connectionFactory.createConnection();
>        try {
>            ...
>        } finally {
>            connection.close();
>        }
>    }
> }
>
>
> - Paul
>
>
> ---
>
> This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
>
> Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.

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


Re: How to create analog of Spring FactoryBean?

Posted by Paul Field <pa...@db.com>.
Hi Andrey,

"Thiago H. de Paula Figueiredo" <th...@gmail.com> wrote on 08/09/2009 
15:51:14:

> Em Tue, 08 Sep 2009 11:27:06 -0300, Andrey Larionov 
<an...@gmail.com> 
> escreveu:
> 
> > No, FactoryBean can create new instance on every call of getObject.
> 
> Then you can create a new Tapestry-IoC scope (ServiceLifecycle 
> implementation) that creates a new object everytime an injection is 
made.

Do  you mean you want a service that acts like a "prototype" bean in 
Spring? You could create a new scope as Thiago suggests but you are likely 
to end up with a service that creates a new underlying object for every 
method call - and that probably isn't what you want.

I suggest simply creating a service that is a Factory; maybe something 
like this:

public final class AppModule {
    public static void bind(ServiceBinder binder) {
        binder.bind(ConnectionFactory.class, ConnectionFactoryWithPool.
class);
    }
}


public interface ConnectionFactory {
    Connection createConnection();
}


public class ConnectionFactoryWithPool implements ConnectionFactory {

    ....

    public Conection createConnection() {
        return pool.getConnection();
    }
}


public class MyPage {
    @Inject
    private ConnectionFactory connectionFactory;

    public void myAction() {
        Connection connection = connectionFactory.createConnection();
        try {
            ...
        } finally {
            connection.close();
        }
    } 
}


- Paul


---

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.

Re: How to create analog of Spring FactoryBean?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Tue, 08 Sep 2009 11:27:06 -0300, Andrey Larionov <an...@gmail.com>  
escreveu:

> No, FactoryBean can create new instance on every call of getObject.

Then you can create a new Tapestry-IoC scope (ServiceLifecycle  
implementation) that creates a new object everytime an injection is made.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Re: How to create analog of Spring FactoryBean?

Posted by Sebastian Hennebrueder <us...@laliluna.de>.
Andrey Larionov schrieb:
> If i provide a factory bean as a property value, Spring use getObject
> return, to set property.
> 
> On Tue, Sep 8, 2009 at 18:27, Andrey Larionov<an...@gmail.com> wrote:
>> No, FactoryBean can create new instance on every call of getObject.
>>
>> On Tue, Sep 8, 2009 at 18:10, Sebastian Hennebrueder<us...@laliluna.de> wrote:
>>> Spring or Pico Container or Guice or whatevery you like.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
With one I didn't mean a singleton but rather one kind of type.

-- 
Best Regards / Viele Grüße

Sebastian Hennebrueder
-----
Software Developer and Trainer for Hibernate / Java Persistence
http://www.laliluna.de



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


Re: How to create analog of Spring FactoryBean?

Posted by Andrey Larionov <an...@gmail.com>.
If i provide a factory bean as a property value, Spring use getObject
return, to set property.

On Tue, Sep 8, 2009 at 18:27, Andrey Larionov<an...@gmail.com> wrote:
> No, FactoryBean can create new instance on every call of getObject.
>
> On Tue, Sep 8, 2009 at 18:10, Sebastian Hennebrueder<us...@laliluna.de> wrote:
>> Spring or Pico Container or Guice or whatevery you like.
>

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


Re: How to create analog of Spring FactoryBean?

Posted by Andrey Larionov <an...@gmail.com>.
No, FactoryBean can create new instance on every call of getObject.

On Tue, Sep 8, 2009 at 18:10, Sebastian Hennebrueder<us...@laliluna.de> wrote:
> Spring or Pico Container or Guice or whatevery you like.

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


Re: How to create analog of Spring FactoryBean?

Posted by Sebastian Hennebrueder <us...@laliluna.de>.
Andrey Larionov schrieb:
> I want to remove a spring part from my project if possible. But i need
> analog of spring FactoryBean. Read documentation but dosnt found any
> point. I think solution is near of ObjectLocator or ObjectProvider,
> but have no idea how to start. Anybody solve this problem?
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
Hello,

as far as I remember a SpringFactoryBean creates only one service or 
bean. An ObjectProvider is something like a beanContext. It allows to 
integrate Spring or Pico Container or Guice or whatevery you like.

You might be interesting in the buildFoo methods in the AppModule
http://tapestry.apache.org/tapestry5.1/tapestry-ioc/service.html
and in Advisor or Decorator.
-- 
Best Regards / Viele Grüße

Sebastian Hennebrueder
-----
Software Developer and Trainer for Hibernate / Java Persistence
http://www.laliluna.de



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


Re: How to create analog of Spring FactoryBean?

Posted by Andrey Larionov <an...@gmail.com>.
Just more specific info. In spring i have FactoryBean for connections
pool. it answers on FactoryBean.getObject calls with some db
connection object.

On Tue, Sep 8, 2009 at 18:01, Andrey Larionov<an...@gmail.com> wrote:
> I want to remove a spring part from my project if possible. But i need
> analog of spring FactoryBean. Read documentation but dosnt found any
> point. I think solution is near of ObjectLocator or ObjectProvider,
> but have no idea how to start. Anybody solve this problem?
>

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