yan2.registerValue("target arrived!");
assertEquals("target arrived!", yan.getInstance("target"));
}
public void testLifeycles()
throws Throwable{
final Container yan = new DefaultContainer();
final Component real_engine =
Components.useKey("real engine").singleton(new ThreadLocalScope());
final DefaultLifecycleDescriptor desc = new DefaultLifecycleDescriptor();
desc.setCloser(new Phase(desc.getCloser().getPhaseKey(), ExceptionHandlers.suppresser()));
desc.setStopper(new Phase(desc.getStopper().getPhaseKey(), ExceptionHandlers.suppresser()));
final DefaultLifecycleManager lm = new DefaultLifecycleManager(desc);
final DefaultLifecycleManager.DefaultLifecycle lc = lm.newLifecycle()
.starter("start")
.stopper("stop")
.initializer("initialize")
.disposer("destroy");
final Component engine_lc = lc.manage(real_engine);
yan.registerComponent(CarEngine.class, engine_lc);
/*
yan.registerComponent(CarEngine.class, LifecycleDescriptor.instance(
Components.useKey("real engine").singleton(new ThreadLocalScope()),
ExceptionHandlers.suppresser())
.starter("start")
.stopper("stop")
.initializer("initialize")
.disposer("destroy")
.get());
*/
yan.registerConstructor("real engine", CarEngine.class);
final Component sttfrc = Components.ctor(StatefulResource.class)
.withArgument(0, Components.useType(CarEngine.class));
yan.registerComponent(lc.manage(sttfrc));
/*
yan.registerComponent(LifecycleDescriptor.instance(
Components.ctor(StatefulResource.class)
.withArgument(0, Components.useType(CarEngine.class))
, ExceptionHandlers.suppresser())
.initializer("initialize")
.disposer("destroy")
.starter("start")
.stopper("stop")
.get());
*/
final Component car_engine = yan.getComponentOfType(CarEngine.class);
assertNull(car_engine.getType());
final StatefulResource resource = (StatefulResource)yan.getInstanceOfType(StatefulResource.class);
final CarEngine engine = (CarEngine)yan.getInstanceOfType(CarEngine.class);
assertEquals(0, engine.getStarted());
assertEquals(0, engine.getStopped());
assertEquals(0, engine.getInit());
assertEquals(0, engine.getDisposed());