且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用匕首模块没有与QUOT;&其注入QUOT;指示

更新时间:2023-02-17 12:11:44

您想

@Module(library=true)

下面就是文档说关于

假如果是必要的,以满足其所有注射类型的该模块中的所有包含绑定。如果一个模块是不是一个库模块,它是获附加静态检查:工具可以检测是否包含绑定是没有必要的。 如果您提供的不使用该模块的图形绑定,那么您必须声明库=真。

False if all the included bindings in this module are necessary to satisfy all of its injectable types. If a module is not a library module, it is eligible for additional static checking: tools can detect if included bindings are not necessary. If you provide bindings that are not used by this module's graph, then you must declare library = true.

(重点煤矿)

声明为库不缓解匕首的需要了解注射点的模块。你还必须声明与上市器喷射对象图的模块。

Declaring a module as a library does not alleviate the needs of Dagger to know about injection points. You still must declare a module in the object graph with the listed injects.

你的榜样的一个极端简化的版本是这样的:

An extreme simplified version of your example would look like this:

repo/
 +- library/
 |   +- Foo.java
 |   `- FooModule.java
 |
 `- app/
     +- BarActivity.java
     `- BarModule.java

FooModule.java

@Module(library = true)
public final class FooModule {
  @Provides @Singleton provideFoo() {
    return Foo();
  }
}

BarModule.java

@Module(
  injects = BarActivity.class,
  includes = FooModule.class
)
public final class BarModule {
}

BarActivity.java (或类似):

ObjectGraph og = ObjectGraph.create(new BarModule());
og.inject(this);