The way I understand it, you can use the Wirebox DSL in this fashion (just an example).
map(“MySettingBean”).toFactoryMethod(factory=“SettingFetcher”, method=“getSomeSettingBean”).methodArg(name=‘settingGroup’, value=‘SecuritySettings’);
However, I found myself trying to do something a little different, and after poring over the Wirebox docs for about 30 minutes, realized I couldn’t do it. Here’s an example of what I was trying, to use the factoryMethod in conjunction with initArg() and/or property() calls.
map(‘SettingService’).to(‘com.company.package.settings.settingService’).asSingleton();
map(‘SpecialService’).to(‘com.company.package.special.specialService’).asSingleton()
.property( name=‘oIOCProvider’, dsl=‘provider:wirebox’ )
.property( name=‘oServiceFactoryProvider’, dsl=‘provider:ServiceFactory’ )
.initArg( name=‘someFilePath’, factoryMethod=( { ‘factory’ = ‘SettingService’, ‘method’ = ‘getSetting’, ‘methodArgs’ = {‘name’=‘settingKey’, 'value=‘someFilePath’} } ) )
.initArg( name=‘someFilePassword’, factoryMethod=( { ‘factory’ = ‘SettingService’, ‘method’ = ‘getSetting’, ‘methodArgs’ = {‘name’=‘settingKey’, 'value=‘someFilePassword’ '} } ) )
Now, this might seem overly complex, and maybe it is. But it seemed that there should be a way to use the factoryMethod technique to pass specific initArg() or property() values to an object. Obviously the syntax above is just made up.
Is there a way to do this currently? I’m sure answers like “pass the entire settingsService” aren’t exactly what I’m looking for. With this particular service layer I’m setting up, I’m really thinking in terms of testing and mocking, and also re-use from apps that don’t necessarily have Wirebox available. (I’m doing no internal injection properties, everything is defined from the Wirebox config.)
In addition, everything is lazy-loaded, so I don’t want to immediately create either of these objects so that I can use the value=oSettingObject.getSetting(…) style. Clearly when the “SpecialService” gets created by Wirebox, it’ll be creating the “SettingService”, too, since that dependency would exist.
Suggestions? Thoughts? Am I overlooking something so simple in my complexity?