bineanzhou / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Cross module singletons (true singletons) #176

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Currently it is not possible to enforce that a certain instance be a
singleton across multiple modules in the same JVM.  This is most visible in
a J2EE context where you have several instances (maybe of the same module)
which are bound to create multiple injectors, or at least one for each
entry-point; e.g. Web services, struts2, EJB.  

When using a pool of resources which is finite for a JVM you may want to
force this finite allocation across multiple modules - for example if there
can only be 25 open handles to some native software.  This could be done
with a singleton which manages a pool; however this singleton must
obviously be single for the whole JVM, otherwise more than 25 handles could
be opened.

It would be great if a class could be bound as @TrueSingleton or bound in a
scope which was available to all modules in the JVM (essentially a static
scope).  This would allow Guice management of true singletons.

Original issue reported on code.google.com by mpetz...@gmail.com on 14 Jan 2008 at 3:54

GoogleCodeExporter commented 9 years ago
You'll be able to accomplish this with injector chaining. See issue 45, or by 
writing your own scope 
"StaticSingleton"

Original comment by limpbizkit on 6 Jun 2008 at 4:24