[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: Handling contexts in error
adrian@jboss.org
do-not-reply at jboss.com
Wed Feb 20 08:54:50 EST 2008
"julien at jboss.com" wrote :
| Please try to get an answer understandable by someone that has little knowledge about MC.
This isn't really an MC question, it's a programming patterns question :-)
The answer is to use a factory/singleton pattern.
e.g. These two would use the object constructed by MyFactory
(which can also be an instance class rather than the shown static method).
| <bean name="Bean1">
| <constructor factoryClass="MyFactory" factoryMethod="getInstance"/>
| </bean>
|
| <bean name="Bean2">
| <constructor factoryClass="MyFactory" factoryMethod="getInstance"/>
| </bean>
|
| ALTERNATIVE:
|
| If you don't like the boiler plate of coding a singleton factory,
| I wrote an aspect that does it for you:
| http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossas/projects/aop/trunk/aspects/src/main/org/jboss/aspects/patterns/singleton/Singleton.java?revision=63048&view=markup
| which I guess could also be configured with an annotation (although it doesn't exist currently).
|
|
| | <bind pointcut="execution(@com.acme.Singleton->new())">
| | <advice name="constructorAdvice" aspect="Singleton"/>
| | </bind>
| |
| | @com.acme.Singleton
| | public class MyBean {}
| |
|
| I'm sure you can adapt it to your needs if it doesn't do exactly what you want. ;-)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4130750#4130750
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4130750
More information about the jboss-dev-forums
mailing list