在 Dagger 2 中是否可以选择使用组件?
Is a Component optional to use in Dagger 2?
http://www.vogella.com/tutorials/Dagger/article.html#connecting-consumers-and-providers and other approch without using Component here http://antonioleiva.com/dagger-android-part-2/中提到了一种方法。
首先,请注意 Dagger 2 和 Dagger不是同一件事。如果您阅读 ObjectGraph
,您可能正在阅读 Dagger (1)。
您不能在没有组件的情况下使用 Dagger 2。组件是保存您的依赖项并知道如何提供和注入它们的对象。我认为 Dagger 1 的 ObjectGraph 也是如此。如果您无法提供依赖项,则无法使用 DI。
http://www.vogella.com/tutorials/Dagger/article.html#connecting-consumers-and-providers and other approch without using Component here http://antonioleiva.com/dagger-android-part-2/中提到了一种方法。
首先,请注意 Dagger 2 和 Dagger不是同一件事。如果您阅读 ObjectGraph
,您可能正在阅读 Dagger (1)。
您不能在没有组件的情况下使用 Dagger 2。组件是保存您的依赖项并知道如何提供和注入它们的对象。我认为 Dagger 1 的 ObjectGraph 也是如此。如果您无法提供依赖项,则无法使用 DI。