Search code examples
androidkotlinmvvmdnsdagger-hilt

Make domain module pure kotlin


I developed a modular android application, but i have a problem in making domain module pure kotlin. I mean, i want my domain module be a kotlin (or java) library, not an android library. everything is ok till i use hilt to inject my repository interface into my usecase. Here i face some error.because hilt is an android library and i shouldn't use it. But i need it. as you can see :

import com.example.domain_article.repository.ArticleRepository
import javax.inject.Inject

class GetArticleListLocalUseCase @Inject constructor(
    private val articleRepository: ArticleRepository) {
    operator fun invoke() = articleRepository.getArticleListLocal()
}

here we have @Inject which belongs to hilt (dagger) and if i remove hilt dependency from gradle of domain module i will get an error.

what should i do to make my domain pure kotlin and hilt?


Solution

  • I faced this before,

    You can import the following:

    import javax.inject.Inject
    

    This would give @inject without adding dagger-hilt to your domain module.

    @Inject belongs to javax inject as said by @IR42 in comments

    And in order to use this library you can

    implementation 'javax.inject:javax.inject:1'