Introducing SwiftSuspenders
Working with RobotLegs
Recently, I started working with the awesome MVCS framework RobotLegs by Shaun Smith.
As I’m not a big fan of the configuration overhead that the Spring framework for Dependency Injection brings with it, I immediately fell in love with the metadata based SmartyPants IOC framework. While I really like the approach and everything worked great, I quickly realized that SmartyPants has two problems: It’s somewhat slow and, due to some dependencies on the Flex framework, rather big.
SwiftSuspenders: A fast, lightweight DI solution
That’s why I started implementing an ultra lightweight DI framework (which hardly even deserves being called a framework) which then became SwiftSuspenders.
SwiftSuspenders implements exactly the functionality needed by RobotLegs, nothing more, but, crucially, nothing less – and it does so as fast and as lean as possible. By focusing on these needs, I was able to implement a solution that’s about an order of magnitude faster and weighs only 10% of SmartyPants file size-wise. And yes: Both of these values are SWAGs and shouldn’t be relied on for, well, anything.
Right after I published SwiftSuspenders on GitHub – as you should do with everything you build that might be of help to your esteemed colleagues – awesome stuff happened: Shaun Smith immediately forked to project, started fixing bugs and embarrasing mistakes in the documentation and switched most of the examples for RobotLegs to using SwiftSuspenders and hinted at creating unit tests – which I shamefully neglected. Yesterday, he followed up on that and pushed a range of unit tests to a new GitHub project!
What now?
Apart from you reading the introductory documentation, starting to use SwiftSuspenders and forking it on GitHub? I’m not sure.
I think that maybe, SwiftSuspenders is pretty much done as it is. SmartyPants still has some features that SwiftSuspenders doesn’t, but for now, I don’t think that those are really essential. Then again, I might implement Provider Binding and Rule Binding sometimes later – whereas I can almost guarantee that I won’t implement live bindings.
7 Comments »
RSS feed for comments on this post. TrackBack URI
Hi Till,
great work! I’ve started a few days ago with my first RobotLegs Project and encountered the same issues.
Thanks for helping me out
Timo
That’s really nice!
I even want to use it outside of RL.
Size matters
Hey Timo and Nek,
thanks for your comments – I’m really glad you find SwiftSuspenders helpful!
I’m just starting with the concept of IoC and i was between Smartypants and Swift, i decided by Swift. But i got to say, i had to read the documentation for Smartypants to understand more about how this thing works. The Swift documentation for a beginner in the matter is still kinda hard to grasp.
I know: The documentation for SwiftSuspenders doesn’t really try to explain the basic concepts of automated dependency injection at all.
Do you have any suggestions on how I could introduce these basics without hiding the actual details of how SwiftSuspenders can be used? Maybe a short introduction with a good collection of links to articles about DI/ IoC would work?
Hi Till,
Have you done any performance comparisons with spring?
Thanks!
Hi Daniel,
no, I didn’t, but I’m fairly confident that SwiftSuspenders is at least as fast as Spring.
The performance bottleneck in DI containers is in how exactly injection mappings are resolved, and I doubt that that can be made much faster than it is in SwiftSuspenders.
If you really need to know how Spring and SwiftSuspenders compare in this regard and end up doing some benchmarks yourself, I’d be very interested in the results, though.