Inject Interface with Generics in Hilt

Viewed 559

I am trying to use Hilt to inject a generic interface implementation but it keep gives me errors

My interface looks like this:

interface Validator<in T> {
  fun validate(value: T): Boolean
}

And a typical implementation of it can be like this:

class FullNameValidator @Inject constructor() : Validator<String>{

   override fun validate(value: String): Boolean {
      val isValid = //Validation logic

      return isValid
    }
}

Now the way I am trying to use Hilt, i've tried to use @Bind method in a @Module like this

@Binds
abstract fun bindFullNameValidator(validator: FullNameValidator) : Validator<String>

Like i am doing with all interfaces implementations and its working just fine But here, Hilt claims that it cannot find a way to inject the String object which is the generic type.

Is there a proper way to inject such interface

0 Answers
Related