Autowiring + Factory Method

37 views
Skip to first unread message

Rawlins

unread,
Jan 2, 2012, 9:27:29 AM1/2/12
to coldspri...@googlegroups.com
Hello Guys,

I'm a keen user of LogBox - I have it running several ColdBox/WireBox applications, however I'm now looking to implement it with a ColdSpring based project.

The logbox library implements a kind of factory method (at least that's what I gather) in which you access the given loggers like logbox.getLogger('name.of.logger');

When used in conjunction with Wirebox, you can use a specific DSL to have given loggers injected into service, rather than the actual logbox instance.

For instance in one of my services I can put something like this:

property name="logger" inject="Logbox:Logger:name.of.logger";

This then injects the specific logger from the logger factory method. This saves me having to define each logger separately in the framework config, I need only define the factory and the auto-wire is smart enough to know how to use it.

Can I do something similar to this with ColdSpring? I've not seen it mentioned anywhere before.

Thanks.

Robert

Chris Blackwell

unread,
Jan 2, 2012, 11:06:56 AM1/2/12
to coldspri...@googlegroups.com
I've never used logbox, but if you have a bean for the logbox factory, you can create a singleton instance of a specific logger by doing

<bean id="LogBox" class="coldbox.system.logging.LogBox" />

<bean id="MyLogger" factory-bean="LogBox" factory-method="getLogger">
  <constructor-arg name="category"><value>name.of.logger</value></constructor-arg>
</bean>

then inject MyLogger into whatever you need.

Chris


--
You received this message because you are subscribed to the Google Groups "ColdSpring-Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/coldspring-users/-/SE0g9BssvMIJ.
To post to this group, send email to coldspri...@googlegroups.com.
To unsubscribe from this group, send email to coldspring-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/coldspring-users?hl=en.

Robert Rawlins

unread,
Jan 2, 2012, 11:22:10 AM1/2/12
to coldspri...@googlegroups.com
Thanks Chris,

That's certainly an option, given the number on classes that could be generated by the factory that would still be quite verbose from an XML standpoint - which is why I was keen to find some form of autowire description that could do the same job.

Thanks.

Robert

Sent from my iPhone

Mark Mandel

unread,
Jan 2, 2012, 8:06:58 PM1/2/12
to coldspri...@googlegroups.com
Sounds like something we may need to look at when we tackle annotations.

Mark
Reply all
Reply to author
Forward
0 new messages