Put your run-time configuration in configuration files, not in your application structure

1 view
Skip to first unread message

darscan

unread,
Apr 21, 2009, 9:51:49 AM4/21/09
to Smartypants IOC
Howdy Josh,

On the SmartyPants Google Code homepage you mention: "Put your run-
time configuration in configuration files, not in your application
structure."

Sounds good. But I'm a little slow sometimes.. Is there a recommended
way to do this? I see that with Guice, one implements modules to set
up rules. Do you have an example of how we might do this (or something
similar) with SmartyPants? How do you do it in your apps?

Thanks!
shaun

darscan

unread,
Apr 21, 2009, 10:05:13 AM4/21/09
to Smartypants IOC
Arg, and this is probably very much related. From the Guice User's
Guide:

"The idea of bootstrapping is fundamental to dependency injection.
Always explicitly asking the Injector for dependencies would be using
Guice as a service locator, not a dependency injection framework."

Which is exactly what I fear I've been doing! Bugger! Back to the
drawing board...

Josh McDonald

unread,
Apr 21, 2009, 10:06:54 AM4/21/09
to smartyp...@googlegroups.com
Something similar to Guice modules will be coming soon, but that's not really what I meant. What you see often in Spring projects is things like database connection information mixed in with the bean definitions, which while you can get away with it in Spring because the bean definitions are parsed at run time rather than being compiled, it really grinds my gears :)

My philosophy is to define the app structure itself in rules via ActionScript, and anything that would vary from server to server (in our case it's mainly WSDL urls) we put into a config.xml file, which is served from the same location as the SWF.

There's nothing particularly clever in our config file decoder, it's about a page of code. At Pathways I built a fairly extensive application framework that sits atop SmartyPants-IOC, and as part of the bootstrap lifecycle it just instantiates a Config("config.xml"), and then inspects the parsed info, creating rules to bind the values as Strings.

A config name/value pair of

<param name="wsdl" value="http://server.com/main.wsdl"/>

becomes SmartyPants.whenAskedFor(String).named("config::wsdl").useValue("http://server.com/main.wsdl");

-Josh

2009/4/21 darscan <Dar...@gmail.com>



--
"Therefore, send not to know For whom the bell tolls. It tolls for thee."

Josh 'G-Funk' McDonald
  -  jo...@joshmcdonald.info
  -  http://twitter.com/sophistifunk
  -  http://flex.joshmcdonald.info/

Reply all
Reply to author
Forward
0 new messages