title: Android Dagger-Hilt How to do Field Injection in abstract class?
body: <p>I am using Dagger-Hilt for Dependency Injection, and I am stuck with not knowing how to do field injection inside an abstract class.</p>
  <pre><code>// @ViewModelScoped
  abstract class BaseUseCase&lt;Params, Return&gt;{
      // lateinit var not initiazlied. Cannot be injected
      @Inject
      lateinit var errorHandler: ErrorHandler
  
      fun execute(@nullable params: Params?=null): Flow&lt;DataState&lt;Return&gt;&gt; = flow {
          emit(Datastate.Loading)
          emit(executeRealization(params))
          ...
      }.catch{ e-&gt;
          when(e){
              ...
              is Exception -&gt; {
                  ...
                  errorHandler.handleError(e.message ?: &quot;Unknown Error&quot;)
              }
          }
      }
  
      protected abstract fun executeRealization(@Nullable params: Params?=null): DataState&lt;Return&gt;
  
  }
  </code></pre>
  <p>[DI package]</p>
  <ul>
  <li>I provided &quot;ErrorHandler&quot; as a singleton using dagger-hilt (AppModule.kt)</li>
  <li>Usecases which extend above BaseUseCase are all written for dagger-hilt (UseCaseModule.kt)</li>
  </ul>
  <ol>
  <li><p>I tried providing or binding BaseUseCase class using dagger-hilt such as BaseUseCaseModule.kt, however since it has type parameters, it cannot be binded and also provided.</p>
  </li>
  <li><p>Currently i cannot inject errorHandler inside BaseUseCase class, so just written ErrorHandler 'object' and using it statically. (e.g. Object ErrorHandler {})</p>
  </li>
  </ol>
  <p>Question</p>
  <ol>
  <li>How to do field injection inside abstract class?</li>
  <li>Or Am i missing something?</li>
  </ol>