com.google.inject.daggeradapter

Class DaggerAdapter



  • public final class DaggerAdapter
    extends Object
    A utility to adapt classes annotated with @dagger.Module such that their @dagger.Provides methods can be properly invoked by Guice to perform their provision operations.

    Simple example:

    Guice.createInjector(...other modules..., DaggerAdapter.from(new SomeDaggerAdapter()));
     

    Some notes on usage and compatibility.

    • Dagger provider methods have a "SET_VALUES" provision mode not supported by Guice.
    • MapBindings are not yet implemented (pending).
    • Be careful about stateful modules. In contrast to Dagger (where components are expected to be recreated on-demand with new Module instances), Guice typically has a single injector with a long lifetime, so your module instance will be used throughout the lifetime of the entire app.
    • Dagger 1.x uses @Singleton for all scopes, including shorter-lived scopes like per-request or per-activity. Using modules written with Dagger 1.x usage in mind may result in mis-scoped objects.
    • Dagger 2.x supports custom scope annotations, but for use in Guice, a custom scope implementation must be registered in order to support the custom lifetime of that annotation.

    Author:
    cgruber@google.com (Christian Gruber)
    • Method Detail

      • from

        public static Module from(Object... daggerModuleObjects)
        Returns a guice module from a dagger module.

        Note: At present, it does not honor @Module(includes=...) directives.

Copyright © 2006-2015 Google, Inc.. All Rights Reserved.