Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put Dependency Injection classes in clean architecture

In clean architecture, if I'm organizing my packages by feature. where to put dependency injection Dagger2 class code ?

like image 576
abd3lraouf Avatar asked Oct 25 '25 04:10

abd3lraouf


1 Answers

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.

like image 155
David Rawson Avatar answered Oct 26 '25 19:10

David Rawson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!