In clean architecture, if I'm organizing my packages by feature. where to put dependency injection Dagger2 class code ?
In addition to the good comments you received above, you should group your classes by feature in packages and put the Dagger 2 Component and Module classes in that package.
Refer to the Google Android Architecture Blueprints Dagger/MVP sample.
There is a root package for the Application class and the app-scoped module and component. From that root package, there are the following sub-packages grouped by feature:
addedittask
statistics
taskdetail
tasks
util
Inside the package there are the following classes:
TaskDetailActivity.java
TaskDetailComponent.java
TaskDetailContract.java
TaskDetailFragment.java
TaskDetailPresenter.java
TaskDetailPresenterModule.java
The benefit of doing this is you can use access control to prevent unintended usages of your classes. This fulfils Effective Java Item 13 - Minimize the accesibility of classes and members.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With