Robotlegs, read-only config Value Objects

FlashdevelopI’ve decided to knock a bad habit of using too many static constants in my code. A Config VO provides a less coupled but also injectable recipe. To enforce ‘read-only-mode’ the config VO is mapped to an interface.

In Robotlegs, to map to interface we use mapSingletonOf:

1
injector.mapSingletonOf(IConfig,ConfigVO);

The interface enforces the usage of getters only in our ConfigVO class and could for example look like:

1
2
3
4
5
6
package com.domain.project.feature.api.core {
   public interface IConfig {
      function get numrows():int;
      function get numimages():int
   }
}

What’s needed in our ConfigVO implementation should be evident from the IConfig Interface. Dependency Injection now makes it a breeze to access the ConfigVO from any Model:

1
2
   [Inject]
   public var configVO:IConfig;

Where we type the instance to the Interface!
-(Thanks to RL forum support for clearing out my confusion about this).

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please leave these two fields as-is:

Protected by Invisible Defender. Showed 403 to 173,337 bad guys.