Skip to content

Auto Binding

elandau edited this page Oct 9, 2015 · 20 revisions

Deprecated


@AutoBindSingleton is deprecated in favor of using bindings in Guice modules. @AutoBindSingleton has been the source of numerous problems since it frequently results in unwanted classes being instantiated. Furthermore, @AutoBindSingleton is misleading since it is not a proper Guice scope. For example, any @AutoBindSingleton annotated class that does not also have the @Singleton annotation does not exhibit singleton behavior when that class was not pulled in via classpath scanning.


Using Guice’s modules to add bindings can be cumbersome and tedious. It’s also unnecessary for most simple types of binding. Governator can scan your CLASSPATH to do “auto binding”. There are two types of auto binding supported:

Governator will only scan configured packages from the CLASSPATH. Set the packages to use with the usingBasePackages() method of the LifecycleInjectorBuilder.

See the wiki for AutoBindSingleton or AutoBind for details.