Appendix B. SmartyPants for Adobe Flex
SmartyPants-IOC is a dependency injection framework for use in building Adobe Flex and Flash applications inspired by Google Guice for Java. It’s based on key concepts:
- The class+name key
- Injector requests, usually specified via metadata
- Injector rules, specified using an ActionScript-based DSL
Whether you’re telling SmartyPants-IOC what to provide or sitting around with your hand out asking for a dependency, the key is the same: a combination of a class and a name. You must specify the class, but the name is optional.
How do you actually request that a field be injected? In most circumstances you need to annotate your fields with ActionScript metadata. If you want to request an instance of IServiceInterface, the syntax is simple:
Let’s say you want to look up a particular string, rather than just anything. For a Web Services Description Language (WSDL) URL, or something along those lines, use this syntax:
These fields will be injected into your object when it’s constructed for you by SmartyPants-IOC or when you call injector.injectInto(myInstance).
SmartyPants-IOC also supports live injections, which when coupled with live rules behave like the Flex SDK’s data-binding functionality: