Class DaggerAdapter
- java.lang.Object
-
- com.google.inject.daggeradapter.DaggerAdapter
-
public final class DaggerAdapter extends Object
Adapts 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( DaggerAdapter.from(SomeDaggerModule.class, new AnotherModuleWithConstructor());
For modules with no instance binding methods, prefer using a class literal. If there are instance binding methods, an instance of the module must be passed.
Any class literals specified by
@dagger.Module(includes = ...)
transitively will be included. Modules are de-duplicated, though multiple module instances of the same type is an error. Specifying a module instance and a class literal is also an error.Some notes on usage and compatibility.
- Dagger provider methods have a "SET_VALUES" provision mode not supported by Guice.
- 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.
If methods need to be ignored based on a condtion, a
Predicate<Method>
can be used passed toDaggerAdapter.Builder.filter(com.google.common.base.Predicate<java.lang.reflect.Method>)
, as inDaggerAdapter.builder().addModules(...).filter(predicate).build()
. Only the methods which satisfy the predicate will be processed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DaggerAdapter.Builder
Builder for setting configuration options on DaggerAdapter.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DaggerAdapter.Builder
builder()
static Module
from(Object... daggerModuleObjects)
Creates a newDaggerAdapter
fromdaggerModuleObjects
.
-
-
-
Method Detail
-
from
public static Module from(Object... daggerModuleObjects)
Creates a newDaggerAdapter
fromdaggerModuleObjects
.
-
builder
public static DaggerAdapter.Builder builder()
-
-