Monday, October 29, 2012

Governator - Lifecycle and Dependency Injection

By Jordan Zimmerman


Yahhh – PostConstruct me now unt PreDestroy me lay-tuh

Governator

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
Governator is another component in the growing Netflix Open Source Platform. See the Governator website at Github for complete details: https://github.com/Netflix/governator.

Why the name Governator? It Governs the bootstrapping process and all my OSS projects end in "tor" (see: Curator and Exhibitor) - also it makes me laugh ;)

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.

Google Guice

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.

Summary

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