cucumber.runtime.java.guice.impl.GuiceFactory Maven / Gradle / Ivy
package cucumber.runtime.java.guice.impl;
import com.google.inject.Injector;
import cucumber.runtime.Env;
import cucumber.runtime.java.guice.ScenarioScope;
import io.cucumber.core.backend.ObjectFactory;
/**
* Guice implementation of the cucumber.api.java.ObjectFactory
.
*/
public class GuiceFactory implements ObjectFactory {
private final Injector injector;
public GuiceFactory() {
this(new InjectorSourceFactory(Env.INSTANCE).create().getInjector());
}
/**
* Package private constructor that is called by the public constructor at runtime and is also called directly by
* tests.
*
* @param injector an injector configured with a binding for cucumber.runtime.java.guice.ScenarioScope
.
*/
GuiceFactory(Injector injector) {
this.injector = injector;
}
public boolean addClass(Class> clazz) {
return true;
}
public void start() {
injector.getInstance(ScenarioScope.class).enterScope();
}
public void stop() {
injector.getInstance(ScenarioScope.class).exitScope();
}
public T getInstance(Class clazz) {
return injector.getInstance(clazz);
}
}