My project is having feature1Module and feature2Module. These 2 are included in app module
build gradle file.
我的项目有功能1模块和功能2模块。这2个包含在应用程序模块构建Gradle文件中。
implementation project(":feature1Module")
implementation project(":feature2Module")
I can access feature1Module and feature2Module's on app module but not able to access app module from feature1Module module.
我可以访问应用程序模块上的功能1模块和功能2模块,但不能从功能1模块模块访问应用程序模块。
Ex:-
app has DashboardFragment
例如:-应用程序具有DashboardFragment
feature1Module has Feature1Fragment
功能1模块具有功能1碎片
feature2Module has Feature2Fragment
Feature2模块有Feature2碎片
I can navigate DashboardFragment to Feature1Fragment and Feature2Fragment but not able to navigate to DashboardFragment from Feature1Fragment beacause i cannot access DashboardFragment from Feature1Fragment.
我可以将DashboardFragment导航到Feature1Fragment和Feature2Fragment,但无法从Feature1Fragment导航到DashboardFragment,因为我无法从Feature1Fragment访问DashboardFragment。
Please suggest how to achieve this.
请建议如何实现这一点。
更多回答
优秀答案推荐
Feature modules cant depend to app module. You need to create a common module ex common
, then make app and feature module depend on it.
功能模块不能依赖于应用程序模块。您需要创建一个公共模块(例如公共),然后使应用程序和功能模块依赖于它。
Suggestion
建议
common
has interface Router
常见的HAS接口路由器
interface Router {
fun moveToDashboard()
}
app
module
应用程序模块
class AppRouter : Router {
override fun moveToDashboard() {
// your logic here
}
}
feature
module, call to common
功能模块,调用公共
private val router: Router = // init logic, maybe call setter from app
router.moveToDashboard()
更多回答
Thank you and Can you please tell how to do this using dagger hilt DI @dinhlam
谢谢,你能告诉我如何使用Dagger Handt DI@dinhlam来完成这项工作吗?
Because We will be not having AppRouter reference in common to pass in DI's module class
因为我们将不会有公共的AppRouter引用来传递DI的模块类
with hilt, you can provide
an instance of AppRouter and inject it in needed module
使用HILL,您可以提供AppRouter的一个实例并将其注入所需的模块中
我是一名优秀的程序员,十分优秀!