package com.cathive.fx.guice;

import com.google.inject.AbstractModule;
import com.google.inject.Injector;

import javafx.application.Application;

/**
 * @author Benjamin P. Jung
 */
public abstract class GuiceApplication extends Application {

    /**
     * The Guice Injector instance that is being used within
     * the context of this application.
     * @see #createInjector()
     * @see #getInjector()
     */
    private Injector injector;

    /**
     * To make sure that the initialization of Guice-based JavaFX application
     * works flawlessly, the original init method of the base JavaFX Application
     * class is overwritten here. All of the 
     */
    @Override
    public final void init() throws Exception {

        super.init();

        final Class<GuiceApplication> clazz = GuiceApplication.class;
        final GuiceApplication instance = this;

        final Injector inj = createInjector();
        if (inj == null) {
            throw new IllegalStateException("Injector has not been created (yet).");
        }

        // Inject all fields annotated with @Inject into this GuiceApplication instance.
        inj.injectMembers(instance);

        // Create a child injector and bind the instance of this GuiceApplication
        // to any instances of GuiceApplication.class.
        // Note: this means that you cannot have two different subclasses of GuiceApplication
        //       within the same context. A limitation that should usually be not a problem,
        //       though.
        injector = inj.createChildInjector(new AbstractModule() {
            @Override
            protected void configure() {
                bind(clazz).toInstance(instance);
            }
        });

    }

    /**
     * This method initializes the Guice Injector to be used for
     * dependency injection in the context of this application instance.
     * <p>This method <strong>must not</strong> return <code>null</code>.
     * @return
     *     The injector to be used in context of this application.
     */
    public abstract Injector createInjector();

    /**
     * Returns the Google Guice Injector that is used within the context
     * of this JavaFX Application.
     * @return
     *     The Guice Injector that has been created during the initialization
     *     of this JavaFX Application.
     * @see #createInjector()
     */
    public final Injector getInjector() {
        return this.injector;
    }

}

@@ -748,24 +748,63 @@
 er.init();%0A%0A
+        @SuppressWarnings(%22unchecked%22)%0A
         fina
@@ -837,16 +837,23 @@
 clazz = 
+(Class%3C
 GuiceApp
@@ -860,22 +860,29 @@
 lication
-.c
+%3E) getC
 lass
+()
 ;%0A      
@@ -1362,220 +1362,8 @@
 ss.%0A
-        // Note: this means that you cannot have two different subclasses of GuiceApplication%0A        //       within the same context. A limitation that should usually be not a problem,%0A        //       though.%0A
     

Fix binding of Application instance in Guice context