如何组合没有无参数构造函数的模块。我有一个包含多个模块的库,我想在我的应用程序中重用它们。但是,这些模块需要一些参数。以下示例描述了我的设置:
图书馆:
@Module(
library = true
)
public class LibModule1 {
private final String mString;
public LibModule1(String string) {
mString = string;
}
//... provide methods
}
@Module(
library = true,
addsTo = LibraryModule1.class
)
public class LibModule2 {
private final String mString;
public LibModule2(String string) {
mString = string;
}
//... provide methods
}
请注意,LibModule2 依赖于 LibModule1 提供的一些对象。
应用程序: 在我的应用程序中,我将来自 LibModule1 和 LibModule2 的对象注入到一个类中。但我不知道,如何组合这些模块。包含参数不起作用,因为两个模块都没有无参数构造函数。addTo不起作用,因为我需要两个库模块,但是参数让我只设置一个类。创建两个注入我的类MyClass.class的应用程序模块不起作用(一个类只能由一个模块注入,对吧?!)。
@Module(
injects = MyClass.class
)
public class AppModule {
}
我该如何解决这个问题?