The solution with ServiceRegistry seems to me a bit heavyweight.
Guice has modules which help breaking down functionality.
If you need cleanup, just store the reference to the component you
need to do the cleanup for in the module object and call its destroy
method when you destroy the module.
If you have too many of objects to destroy in your module, maybe it is
time to break down the module... :)
Non-singletons is another story... but solution with ServiceRegistry
does not help there anyway.
Piotr Gabryanczyk
On May 17, 5:22 am, "Sam Berlin" <
sber...@gmail.com> wrote:
> Some others have recommended a solution of having a Service interface
> that exposes something like init(), start() & stop(), and having a
> method on all classes that are services:
>
> @Inject register(ServiceRegistry registry) { registry.register(this); }
>
> That'll let every service-class be managed by a registry that can be
> inited, started and stopped. So long as your objects are eager
> singletons, this'll work wonderfully.
>
> Sam
>