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

Help with @Inject, for some reason it doesn't work. #1188

Open
valenpo opened this issue May 24, 2018 · 1 comment
Open

Help with @Inject, for some reason it doesn't work. #1188

valenpo opened this issue May 24, 2018 · 1 comment

Comments

@valenpo
Copy link

valenpo commented May 24, 2018

I have a class i wan't inject
For legacy code support it is like this.

@Singleton
public class Applications extends AbstractModule {
    private Applications() {}
    private static class ApplicationsLoader {
        static final Applications INSTANCE = new Applications();
    }
    @Override    protected void configure() {}

    @Provides @Singleton
    public Applications get() {
        return ApplicationsLoader.INSTANCE;
    }
   public static Applications getApps() {
        return ApplicationsLoader.INSTANCE;
    }
}

On application startup , I create injector.

public void startup() throws Exception {
		initLogging();
		Injector injector = Guice.createInjector(Stage.PRODUCTION, Applications.getApps());
	}

but some while after, when I need Applications.class i always get a null

public class Blob {

    @Inject private Applications applications;
.....
}

Any suggestions how to share Applications.class singleton?
injector.getInstance(Applications.class) working fine.

Regards

@timur-sh
Copy link

timur-sh commented Jun 7, 2018

Do you create a Blob class in appropriate way?

injector.getInstance(Blob.class) 

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