我有一个Controller实例。这是非上下文CDI bean。我想将CDI bean注入我的控制器实例。我这样编码:
MyController controller = myWayToCreateController();
CreationalContext<Controller> ctx = beanManager.createCreationalContext(null);
AnnotatedType<Controller> at = beanManager.createAnnotatedType(MyController.class);
InjectionTarget<Controller> it = beanManager.createInjectionTarget(at);
it.inject( controller, ctx); // LINE 1
it.postConstruct( controller); // LINE 2
// ctx.release(); // LINE 3
// .................
// ......Use controller here
// .................
// Later, I destroy my controller
it.preDestroy(controller); // LINE 4
it.dispose(controller); // LINE 5
ctx.release(); // LINE 6
我的问题是:
Question1: Do I really need LINE 2, LINE 4 since my controller has no @PostConstruct and @PreDestroy.
Question1: Can I use LINE 3 instead of using LINE 6? I just want to release CreationalContext right after my controller initialized.