Governator — Lifecycle and Dependency Injection
by Jordan Zimmerman
Yahhh — PostConstruct me now unt PreDestroy me lay-tuh
Governator is a library of extensions and utilities that extend Google Guice to provide:
- Classpath scanning and automatic binding
- Lifecycle management
- Configuration to field mapping
- Field validation
- Parallelized object warmup
- Lazy singleton support
- Generic binding annotations
What is Dependency Injection?
According to Wikipedia, Dependency Injection “is a software design pattern that allows a choice of component to be made at run-time rather than compile time.” It is also known as the Inversion of Control Pattern which was originally described by Martin Fowler.
As has been described on the Netflix Tech Blog and elsewhere, Netflix utilizes a highly distributed architecture comprised of many individual service types and many shared libraries. The Netflix Platform Team is responsible for making those libraries and services easy to configure and use. As the number of these libraries and services has grown, our existing methods have reached their limits. That is why we’re moving to a Dependency Injection based system. This system will make it much easier for teams to use common libraries without having to worry about initialization and object lifecycle details.
What is Object Lifecycle?
In many programming languages, Java in particular, there is much more to the lifecycle of an object than just its allocation. The object may need to register itself with existing objects, it may need to load property files, it may need to warm caches, etc.
At Netflix, our shared libraries must load dynamic properties before they are ready to be used (see the Tech Blog post regarding Archaius). Additionally, libraries such as Astyanax need to warm internal caches before they can perform at optimum levels. Users of a library shouldn’t need to concern themselves with these details if possible.
Guice is a Dependency Injection container created and open sourced by Google. We’ve decided to standardize on Guice because it is a small library that is well supported, has strong acceptance by the Java community and is relatively easy to extend to our needs. Using a library like Guice makes the introduction of Dependency Injection much easier.
We hope you find Governator as useful as we do. We’d appreciate any and all feedback on it. Are you interested in working on great open source software? Netflix is hiring! http://jobs.netflix.com
Archaius is a dynamic, multidimensional properties framework.medium.com
Originally published at techblog.netflix.com on October 29, 2012.