FunnyDevs / hilt-conductor

Apache License 2.0
17 stars 3 forks source link

Dependencies not injected #5

Open man-dh opened 3 years ago

man-dh commented 3 years ago

I am trying to make use of your library, and thanks for sharing it - but I cannot make it work.


@ConductorEntryPoint
class RegisterController:  Controller {
  @Inject lateinit var viewModel: RegisterViewModel
}
@InstallIn(ControllerComponent::class)
@Module
interface ViewModelModule {

  @Binds
  @IntoMap
  @ClassKey(RegisterViewModel::class)
  @ControllerScoped
  fun provideRegisterViewModel(registerViewModel: RegisterViewModel): BaseViewModel

I am using compile and target SDK 31 Any recommendations?

FunnyDevs commented 3 years ago

Hi! Sorry but i haven't already implemented class qualifiers (@ClassKey), so if you need qualifiers you must use @Named

man-dh commented 3 years ago

The issue is possibly somewhere else - even without the ClassKey it won't work.

I created two Dummy controllers to try to figure out what's going on. One that extends Controller Directly and one that extends my BaseController which extends Controller

The first one doesn't even compile:

@ConductorEntryPoint
class DummyController(args: Bundle?) : Controller(args) {

    @Inject
    lateinit var viewModel: ViewModel

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup,
        savedViewState: Bundle?
    ): View {
        System.out.println()
        val view = inflater.inflate(R.layout.controller_dummy_layout, container, false)
        return view
    }
}

The error is: Cause: no such class: .....DummyControllerHiltInterface

The second one does compile:

@ConductorEntryPoint
class DummyController2: BaseController<ControllerDummyLayoutBinding>() {

  @Inject lateinit var viewModel: ViewModel

  override fun attachVariables(viewBinding: ControllerDummyLayoutBinding) {

  }

  override fun onViewBound(viewBinding: ControllerDummyLayoutBinding) {

  }

  override fun getLayout() = R.layout.controller_dummy_layout

}

But the dependencies are not there and it crashes shortly after it's launched with this error:

image

The ViewModel class looks like that:

class ViewModel @Inject constructor(private val dependency1: Dependency1) {

class Dependency1 @Inject constructor() {}
}
FunnyDevs commented 3 years ago

Could i have your dummy project to inspect which is the problem?