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

Get Guice injector created by mvvmFX #612

Open
BowgartField opened this issue Jul 19, 2020 · 1 comment
Open

Get Guice injector created by mvvmFX #612

BowgartField opened this issue Jul 19, 2020 · 1 comment

Comments

@BowgartField
Copy link

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.

@manuel-mauky
Copy link
Collaborator

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

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

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