On Dec 3, 2008, at 11:18 AM, Gavin King wrote:
One thing that we could do, purely in the interest of simplifying
the
spec is to
* eliminate the notion of disposal methods, and
* require that the web bean manager raise an event whenever it created
or destroys any web bean.
Then any web bean could react to creation or destruction of an object
using an observer method:
void prepareFoo(@Observes @Created @SomeBinding Foo foo) { .... }
void disposeFoo(@Observes @Destroyed @SomeBinding Foo foo) { .... }
The overhead would be pretty high, I'd think. The disposal method is
fine, because it's a fairly infrequent use case (@PreDestroy would be
more common), so most people can ignore that part of the spec. In
other words, disposes doesn't really add to the spec complexity, and
it nicely matches with the @Produces method.
As long as you're thinking about events, an event that would be useful
would be a startup event for each Bean after all the class scanning
and XML parsing is complete. With that event, you can do some clever
things like starting up singleton services, similar to the Listeners
in the Servlet spec.
-- Scott
This is not exactly semantically identical to a disposal method, since
disposal methods have the special quality that there is at most one
disposal method per producer method, whereas according to this
proposal, the number of observers of one of these events is unlimited
(which is potentially more powerful and more error-prone).
It's just an idea - something we could do that would make the spec
simpler. I don't think it's necessarily an improvement.
--
Gavin King
gavin.king(a)gmail.com
http://in.relation.to/Bloggers/Gavin
http://hibernate.org
http://seamframework.org