I just realized something. It is not actually transfer.transferFactory
that I need to pass into all of my objects, it is
transfer.TransferFactory.getTransfer() but there doesn't seem to be a
way to do that in LightWire.
In ColdSpring, instead of supplying a class to the bean definition,
you supply a bean-factory attribute with the value of the factory
class. Here is the code in ColdSpring:
<bean id="transferFactory" class="transfer.TransferFactory" singleton="true" >
...
</bean>
<bean id="transfer" factory-bean="transferFactory"
factory-method="getTransfer" singleton="true" />
How can I do this in LightWire? Here is a proposal if nothing already exists:
variables.Bean.transferFactory.Singleton = 1;
variables.Bean.transferFactory.Path = "transfer.transferFactory";
...
variables.Bean.transfer.Singleton = 1;
variables.Bean.transfer.FactoryBean = "transferFactory";
variables.Bean.transfer.FactoryMethod = "getTransfer";
variables.transferFactory =
createObject("component","transfer.transferFactory").init("/#application.name#/config/datasource.xml","/#application.name#/config/transfer.xml","/#application.name#/com/transfer/definitions");
transfer = variables.transferFactory.getTransfer();
But I got the following error:
Element transfer is undefined in a CFML structure referenced as part
of an expression.
The error occurred in
C:\Inetpub\wwwroot\WHMedia\com\util\lightwire.cfc: line 168
Called from C:\Inetpub\wwwroot\WHMedia\com\util\lightwire.cfc: line 62
Called from C:\Inetpub\wwwroot\WHMedia\com\util\lightwire.cfc: line 26
Called from C:\Inetpub\wwwroot\WHMedia\Application.cfm: line 12
166 :
167 : // And we need to add its dependencies to this list if it has any
168 : If (StructKeyExists(variables.Bean[LoopObjectName], KeyType))
169 : {
170 : // Set the parent dependency set for this object
Here is what I had to do:
variables.transferFactory =
createObject("component","transfer.transferFactory").init("/#application.name#/config/datasource.xml","/#application.name#/config/transfer.xml","/#application.name#/com/transfer/definitions");
variables.transfer = variables.transferFactory.getTransfer();
variables.Bean.userService.Singleton = 1;
variables.Bean.userService.Path = "#application.name#.com.user.userService";
variables.Bean.userService.ConstructorProperties.transfer =
"#variables.transfer#";
variables.Bean.userService.SetterDependencies = "userGateway";
Note that I changed it from ConstructorDependencies to
ConstructorProperties.transfer.
I had to try several different combinations of things before I finally
got, but now it will all be worth it.
Thanks for your help Peter!
Best Wishes,
Peter
That was what was coming to me as I saw your final solution including a
createobject in the LightWire config. This makes perfect sense and seems to
be a great enhancement. Will get it in shortly!
Thanks!
Peter