This is no issue. Just add @Inject
to the constructor and hilt can figure it out.
Last active
December 28, 2022 15:24
-
-
Save mitchtabian/fd5a5a4e17700ce23724245d500ebdbd to your computer and use it in GitHub Desktop.
Basics #4: Dependencies that require dependencies (Concrete classes that you own)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import androidx.fragment.app.Fragment | |
import dagger.hilt.android.AndroidEntryPoint | |
import javax.inject.Inject | |
@AndroidEntryPoint | |
class MainActivity : AppCompatActivity() { | |
@Inject | |
lateinit var someClass: SomeClass | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
println(someClass.doAThing()) | |
} | |
} | |
class SomeClass | |
@Inject | |
constructor( | |
private val someDependency: SomeDependency | |
){ | |
fun doAThing(): String{ | |
return "Look I got: ${someDependency.getAThing()}" | |
} | |
} | |
class SomeDependency | |
@Inject | |
constructor(){ | |
fun getAThing() : String{ | |
return "A Thing" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment