Can I inject settings at runtime?

Ruprict's Avatar


17 Jan, 2010 03:07 PM

Pardon me if this is a dumb question or if it's answered on the discussions list (I looked...) but I was wondering how you could set runtime settings on, for example, a service class. A scenario could be moving between test and production, where my test service has a different url or API key or something, and I just want to change that value when I move to production. Also, if the URL of the service changes in prod, I wouldn't want to recompile the whole app to adjust.

Using Spring, this would just go in the XML context file in the definition of the service object. Where does it go in the default implementation of robotlegs?

Thanks for the help,

  1. Support Staff 1 Posted by Till Schneidere... on 17 Jan, 2010 05:03 PM

    Till Schneidereit's Avatar

    Hi Ruprict,

    there's not really any specific place to put such configuration in
    Robotlegs. I think people deal with this quite differently, so I'll
    just state what I normally do:

    The short version is: "in the application's override of
    Context#startup" - the slightly longer version follows:

    For small projects, I do all injector mappings directly in the
    projects' override of Context#startup as can be seen in Joel's
    FlickrImageGallery example[1] and simply do the configuration mappings
    before all other mappings so as to verify availability of the
    configuration parameters to all services.

    For bigger projects, I bind several specialized startup commands to
    the ContextEvent.STARTUP event and make the first one a
    ConfigurationCommand that creates all the injection mappings dealing
    with application configuration.

    Depending on what kind of configuration settings you have to apply,
    you might either use if/ else clauses (e.g. to map the live or the
    testing version of a service) or simply assign a value contained in a
    variable to a mapping (e.g. to map a URL or an API key).

    In most cases, you'll want to have access to the SWF's LoaderInfo or
    at least to the ApplicationParameters to be able to even find out
    which configuration to apply, so your startup method might look
    something like:

    protected override function startup() : void
        injector.mapValue(LoaderInfo, contextView.stage.loaderInfo);
        commandMap.mapCommand(ContextEvent.STARTUP, ConfigCommand,
    ContextEvent, true);
       // further startup command mappings here ...

    That's what I'm using, at least - others might have different/ better recipes.



  2. 2 Posted by borekb on 15 Jul, 2010 02:01 PM

    borekb's Avatar

    Hi Till, I have the same question as the original poster and am not sure if your answer addresses it. So let me ask differently; for instance, Parsley has these ActionScript, MXML and XML configuration options where the first 2 are used at compile time and the last one for runtime configuration.

    Is there a similar option (some kind of textual config that can be loaded at runtime) available in Robotlegs?

  3. 3 Posted by borekb on 09 Aug, 2010 07:46 AM

    borekb's Avatar

    Still no answer here - does Robotlegs support runtime configuration? If not directly, what would be the best way to implement it?

  4. 4 Posted by Ruprict on 09 Aug, 2010 12:47 PM

    Ruprict's Avatar

    Hey borekb,

    If you look at the comments at the end of this post ( odoenet adds a couple of links to how he does it.

    Hope this is useful,

  5. 5 Posted by Nikos on 13 Aug, 2010 04:13 PM

    Nikos 's Avatar

    FMOI why are you moving from spring to RL

  6. Stray closed this discussion on 12 Feb, 2011 10:40 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac