Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependencies not injected #5

Open
man-dh opened this issue Oct 11, 2021 · 3 comments
Open

Dependencies not injected #5

man-dh opened this issue Oct 11, 2021 · 3 comments

Comments

@man-dh
Copy link

man-dh commented Oct 11, 2021

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
Copy link
Owner

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

@man-dh
Copy link
Author

man-dh commented Oct 12, 2021

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
Copy link
Owner

FunnyDevs commented Oct 12, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants