Appendix B. Swiftsuspenders: The power behind the Robotlegs Injector

When Robotlegs was first created, the intention was to leave the choice of which actual injector to use to process metadata to the end user.

The out-of-the-box solution uses an injection container called Swiftsuspenders, created by the brilliant Till Schneidereit. As it turns out, we like the Swiftsuspenders injector so much that it’s unlikely that anybody is actually using anything different, and on a practical level Swiftsuspenders is the Robotlegs Injector, and we expect the two to continue to evolve together.

What does Swiftsuspenders actually do?

Swiftsuspenders essentially does two things: it interrogates classes (using the AS3 reflection capabilities) and it manages the supply of objects to fulfil dependencies using the rules you set up on the injector.

The challenge of automated DI is that AS3 reflection isn’t very efficient, so squeezing every last drop of performance out of the process is difficult but important, and this is where the Swiftsuspenders injector earns its plaudits.

Swiftsuspenders uses caching to limit the number of times each class is described, and does all object instantiation and description as lazily as possible—a class won’t be described, or created, until an instance is required. If you have a reason for wanting your mapped objects to be created and described eagerly, you can deliberately instantiate the class after each mapping (making sure any of its injections have already been mapped): ...

Get ActionScript Developer's Guide to Robotlegs now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.