This is a Hilt question: How to only inject one pa...
# android
p
This is a Hilt question: How to only inject one parameter in a constructor? Having a class like this:
Copy code
@AndroidEntryPoint 
class CustomClass @Inject constructor (val repository: Repository, val name: String) {}
Let's say I only want to inject the repository parameter, but I want to pass the name parameter during initialization like so:
Copy code
val CustomClass = CustomClass("name")
How to do it?
not kotlin but kotlin colored 2
p
So I need to add more boilerplate code, and even a factory, to just add some parameters. I thought using DI framework whould be easier than regular DI or avoiding DI, but I'm a little surprised of the complexity and the boilerplate added by hilt
it seems to be simple for this very reduced sample of code, but doing that in a big project whould imply a lot of interfaces and boilerplate lines
Probably that interface factory can be automatized by hilt, I don't understand why they are forcing users to create it manually
wow, I'm checking that you are forced to use the factory to create the objects, is not used automatically under the hood by hilt
I'm really negatively surprised
@ephemient what do you think about this option? create a normal constructor and only inject the repository:
Copy code
@AndroidEntryPoint 
class CustomClass(val name: String) {
    @Inject lateinit var repository: Repository
}