Dependency injection with clean architecture on Android

so I’ve been reading the last few days about clean architecture and I’ve decided to implement it on my project. The layers I’m using are, from outer layer to inner layer:

  • Framework/UI
  • Data/UseCases
  • Domain

As far as I know, with this approach I can have all of the Android stuff in the outer layer (framework/UI in my case) and the rest can be Kotlin, so I can reuse it the code in the layers of Data/UseCases and Domain for another Kotlin project.

So far so good, the thing is I’m having a problem with the dependency injection. My project has a local database on Room, which I’m developing in the outer layer and also follows the Repository pattern, which is in the data layer. In the constructor of my Repository I’m trying to inject an interface so that I can access the Room database implementeted in the framework layer, the problem is that I’m using Hilt, so if I want to inyect it, I need to use Hilt code, which belongs to the framework layer. As I understand this clean architecture, the data layer should not know about the framework layer, which is impossible in my case as I’m using Hilt for the inyection in the data layer.

Is there something I’m not understanding about the architecture? Is my approach of using Hilt to inject the database to the Repository a bad idea?


Source: Android Questions