I'm porting my Coldspring xml into Wirebox, but I'm stuck.
<map>
in Coldspring can create a struct of singletons and then pass that struct into the 'bean' by constructor or setter. And <list>
creates an array.
What do I write in Wirebox.cfc to do the same thing?
<bean id="Foo" class="com.foo">
<constructor-arg name="something">
<map>
<entry key="apple">
<ref bean="apple"/>
</entry>
<entry key="banana">
<ref bean="banana"/>
</entry>
</map>
</constructor-arg>
</bean>
<bean id="bar" class="com.bar">
<constructor-arg name="anArray">
<list>
<bean class="com.XX"/>
<bean class="com.YY"/>
</list>
</constructor-arg>
</bean>
Update: I have found a clean way to support this after reading how ColdSpring does it.
First, create a cfc with 2 methods:
component
{
struct function buildStruct() {
return arguments;
}
array function buildArray() {
var array = [];
for (var index = 1; index <= arrayLen(arguments); index++)
array[index] = arguments[index];
return array;
}
}
Then in wirebox config.cfc:
map("Factory")
.to("com.util.wirebox.Factory")
.asSingleton()
.noAutowire();
map("something")
.toFactoryMethod(factory="Factory", method="buildStruct")
.methodArg(name="apple", ref="apple")
.methodArg(name="banana", ref="banana");
map("Foo").to("com.Foo").initArg(name="something", ref="something").asSingleton();
Original Answer:
// Map Binder so you can do utility methods
map("myBinder").toValue( this );
// Map the singleton maps
map("s1Map").toFactoryMethod("myBinder", "buildMap")
.methodArg(name="mapType", value="1");
// Map A service with a singleton map
map("Service").to("path")
.initArg(name="myMap", ref="s1Map");
He suggested me to file an ER, and here is it: http://coldbox.assembla.com/spaces/coldbox/support/tickets/1387-support-for--list--and--map--of-coldspring-xml