I’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 |
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).