All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jwebmp.guicedinjection.injections.ContextBinderGuice Maven / Gradle / Ivy

Go to download

Guice Injection allows you to access multiple Guice Binders and Modules across separate archives. Allowing you to configure your applications with injection from multiple dependancies. Servlets, EJB's, and Stand-Alone is supported. Requires JDK 8 or 10.

There is a newer version: 0.66.0.1
Show newest version
package com.jwebmp.guicedinjection.injections;

import com.google.inject.Singleton;
import com.jwebmp.guicedinjection.GuiceConfig;
import com.jwebmp.guicedinjection.GuiceContext;
import com.jwebmp.guicedinjection.abstractions.GuiceInjectorModule;
import com.jwebmp.guicedinjection.interfaces.IGuiceDefaultBinder;
import com.jwebmp.guicedinjection.properties.GlobalProperties;
import com.jwebmp.logger.LogFactory;
import io.github.classgraph.ScanResult;

import java.util.logging.Logger;

/**
 * Binds the basic objects for the Guice Context to be injected everywhere
 */
@SuppressWarnings("unused")
public class ContextBinderGuice
		implements IGuiceDefaultBinder
{
	private static final Logger log = LogFactory.getLog("GuiceContextBinder");

	public ContextBinderGuice()
	{
		//No config required
	}

	@Override
	public void onBind(GuiceInjectorModule module)
	{
		ContextBinderGuice.log.fine("Bound GuiceConfig.class");
		module.bind(GuiceConfig.class)
		      .toProvider(() -> GuiceContext.instance()
		                                    .getConfig())
		      .in(Singleton.class);

		ContextBinderGuice.log.fine("Bound GlobalProperties.class");
		module.bind(GlobalProperties.class)
		      .asEagerSingleton();

		ContextBinderGuice.log.fine("Bound ScanResult.class");
		module.bind(ScanResult.class)
		      .toProvider(() -> GuiceContext.instance()
		                                    .getScanResult())
		      .in(Singleton.class);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy