sialcasa / mvvmFX

an Application Framework for implementing the MVVM Pattern with JavaFX
Apache License 2.0
489 stars 105 forks source link

dagger as DI #628

Closed brijesh-padsala closed 1 year ago

brijesh-padsala commented 1 year ago

I want to inject some class in Viewmodel using Dagger2 DI framework. How can i set custom DI for dagger-2 ?? any help ?

manuel-mauky commented 1 year ago

Hi, MvvmFX needs to get instances of a class at runtime. See https://github.com/sialcasa/mvvmFX/wiki/Dependency-Injection#other-dependency-injection-frameworks for a short description. You need to call MvvmFX.setCustomDependencyInjector and pass it a callback function. That function takes a Class as argument and has to return an instance of that class.

I'm not sure about this but if I remember correctly, Dagger is doing compile-time DI while mvvmFX needs runtime-DI. If dagger provides a way to dynamically get instances of a specific class, you should be able to get it to work with the custom injection as described above.

brijesh-padsala commented 1 year ago

Hey,

Thanks for answering. As Dagger is compile time DI. I didn't found way to set Custom DI for dagger. But I found other way around to Inject DI in Viewmodels.

Thanks for your time.