io.github.factoryfx.copperbridge.CopperEngineContextFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of copperBridge Show documentation
Show all versions of copperBridge Show documentation
factoryfx dependency injection framework
package io.github.factoryfx.copperbridge;
import java.util.Map;
import io.github.factoryfx.factory.attribute.dependency.FactoryAttribute;
import io.github.factoryfx.factory.attribute.types.StringAttribute;
import io.github.factoryfx.factory.FactoryBase;
import org.copperengine.core.tranzient.TransientScottyEngine;
public abstract class CopperEngineContextFactory> extends FactoryBase {
public final StringAttribute dependencyInjectorType = new StringAttribute().labelText("DependencyInjectorType");
public final FactoryAttribute> transientScottyEngine = new FactoryAttribute>().labelText("Transient engine").nullable();
public final FactoryAttribute> persistentScottyEngine = new FactoryAttribute>().labelText("Persistent engine").nullable();
public CopperEngineContextFactory(){
configLifeCycle().setCreator(()->{
// Here we need to break the ffx dependency injection, because we don't need a new engine in case of a dependency change
CopperEngineContext dependencyInjector = new CopperEngineContext(dependencyInjectorType.get(), createDependencyHashMap());
if(transientScottyEngine.instance()!=null) transientScottyEngine.instance().setDependencyInjector(dependencyInjector);
if(persistentScottyEngine.instance()!=null) persistentScottyEngine.instance().persistentProcessingEngine.setDependencyInjector(dependencyInjector);
return dependencyInjector;
});
}
public abstract Map createDependencyHashMap();
}