mvvmFX icon indicating copy to clipboard operation
mvvmFX copied to clipboard

Get Guice injector created by mvvmFX

Open BowgartField opened this issue 4 years ago • 1 comments

Hello, I created a class called StageBuilder which need the same instance of a class B as which is in the ViewModel of my class. I have two classes: StageBuilder and ExampleView. The role of stageBuilder is to load the stage form the FluentViewLoader and attache ressources and windows title.

Those two classes need the same instance of classes B because StageBuilder save the Stage created in a List contained in the class B, and class B is used in ExampleView too. But for now, ExampleView is instanciate by mvvmFX so @Inject annotation is trigered by internal mvvmFX injector. And my StageBuilder is created by my own injector, so this result on a different instance of class B in StageBuilder and ExampleView. My class B is annoted with @Singleton and load in my Guice Module with .asEagerSingleton();

To load the same B instance in StageBuilder I need to get the injector of mvvmFX.

Thanks.

BowgartField avatar Jul 19 '20 09:07 BowgartField

You can inject the guice injector in you main app class like this:

class MyApp extends MvvmfxGuiceApplication {
	@Inject
	private Injector injector;
	
	...
}

manuel-mauky avatar Oct 23 '20 13:10 manuel-mauky