uk.sponte.automation.seleniumpom.dependencies.GuiceDependencyInjector Maven / Gradle / Ivy
package uk.sponte.automation.seleniumpom.dependencies;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.Stage;
import uk.sponte.automation.seleniumpom.PageFactory;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Logger;
/**
* Created by evops on 05/02/2016.
*/
public class GuiceDependencyInjector extends AbstractModule implements DependencyInjector {
private final static Logger LOG = Logger.getLogger(GuiceDependencyInjector.class.getName());
private Injector injector;
private HashMap factories = new HashMap();
protected ArrayList modules = new ArrayList();
private PageFactory pageFactory;
public GuiceDependencyInjector(PageFactory pageFactory, DependencyFactory... factories) {
this.pageFactory = pageFactory;
modules.add(this);
for (DependencyFactory factory : factories) {
registerFactory(factory);
}
}
private Injector getInjector() {
if(this.injector != null) return injector;
injector = Guice.createInjector(Stage.PRODUCTION, modules);
return injector;
}
@Override
protected void configure() {
// Register custom factories
for (Type type : this.factories.keySet()) {
bind(((Class
© 2015 - 2024 Weber Informatics LLC | Privacy Policy