| Currently, CDI beans are held in a map, and released on shutdown. This is not ideal, as some beans may only be used during bootstrap, so we could release them earlier. One way to solve this would be to make BridgeBuilder and BeanResolver return a "releasable" BeanReference, so that ManagedBeans from CDI/Spring (obtained through Hibernate ORM) can be properly released. This would also allow users to properly release their own CDI beans, for instance those built using an Instance<MyBridge> and returned by a custom BridgeBuilder: users would be able to implement a BeanReference that calls instance.destroy( bean ) upon release. We should probably rename the current "BeanReference" to something else, though, such as "BeanSelection" or "BeanCoordinates". The name doesn't matter much, it's SPI. Also, the fact that most of or beans extend AutoCloseable makes CDI lifecycle a bit confusing: should users add a @PreDestory method? Should they simply add code to #close()? Both? I would personally be in favor of removing the close() method from user-provided components. I would make the reflection-based bean provider return a CloseableBeanReference whenever a user bean implements AutoCloseable. This reference would just call close() when release() is called, wrapping the exception with a RuntimeException if necessary. |