modules) throws Exception {
+
+
+ /**
+ * This method is called by the javafx runtime when the application is initialized.
+ * See {@link Application#init()} for more details.
+ *
+ * In this method the initialization of the guice container is done.
+ * For this reason, this method is marked as final and cannot be overwritten by users.
+ *
+ * Please use {@link #initMvvmfx()} for your own initialization logic.
+ *
+ * @throws Exception
+ */
+ public final void init() throws Exception {
+ List modules = new ArrayList<>();
+
modules.add(new MvvmfxModule());
modules.add(new AbstractModule() {
@Override
protected void configure() {
- bind(HostServices.class).toProvider(new Provider() {
- @Override
- public HostServices get() {
- return getHostServices();
- }
- });
+ bind(HostServices.class).toProvider(MvvmfxGuiceApplication.this::getHostServices);
- bind(Stage.class).toProvider(new Provider() {
- @Override
- public Stage get() {
- return primaryStage;
- }
- });
+ bind(Stage.class).toProvider(() -> primaryStage);
- bind(Parameters.class).toProvider(new Provider() {
- @Override
- public Parameters get() {
- return getParameters();
- }
- });
+ bind(Parameters.class).toProvider(MvvmfxGuiceApplication.this::getParameters);
}
});
this.initGuiceModules(modules);
+
+ final Injector injector = Guice.createInjector(modules);
+ MvvmFX.setCustomDependencyInjector(injector::getInstance);
+
+ injector.injectMembers(this);
+
this.initMvvmfx();
}
@@ -86,8 +84,7 @@ public Parameters get() {
*/
public final void start(Stage stage) throws Exception {
this.primaryStage = stage;
- MvvmFX.setCustomDependencyInjector(guiceInjector);
-
+
this.startMvvmfx(stage);
}
@@ -97,7 +94,8 @@ public final void stop() throws Exception {
}
/**
- * Configure the guice modules.
+ * Configure your guice modules. Use the given list and
+ * add your modules to it.
*
* @param modules
* module list
diff --git a/mvvmfx-guice/src/main/java/de/saxsys/mvvmfx/guice/internal/MvvmfxModule.java b/mvvmfx-guice/src/main/java/de/saxsys/mvvmfx/guice/internal/MvvmfxModule.java
index 2c28bd3c1..456cd776d 100644
--- a/mvvmfx-guice/src/main/java/de/saxsys/mvvmfx/guice/internal/MvvmfxModule.java
+++ b/mvvmfx-guice/src/main/java/de/saxsys/mvvmfx/guice/internal/MvvmfxModule.java
@@ -16,8 +16,6 @@
package de.saxsys.mvvmfx.guice.internal;
import com.google.inject.AbstractModule;
-import com.google.inject.Provider;
-
import de.saxsys.mvvmfx.MvvmFX;
import de.saxsys.mvvmfx.utils.notifications.NotificationCenter;
@@ -29,13 +27,6 @@
public class MvvmfxModule extends AbstractModule {
@Override
protected void configure() {
- bind(NotificationCenter.class).toProvider(new Provider() {
- @Override
- public NotificationCenter get() {
- return MvvmFX.getNotificationCenter();
- }
- });
-
-
+ bind(NotificationCenter.class).toProvider(MvvmFX::getNotificationCenter);
}
}