google/guice — pull request #871 by mcculls (2014-10-31 19:30:39+00:00)
Title: Request For Enhancement: Scopes.asSingleton(Binding)

The recent change to support finer-grained singleton locks removed
the ability to take a prototype binding from the injector and turn
it into a singleton-scoped provider, using the same lock as if it
had originally been bound as a singleton. It's important that the
same lock is used, otherwise there is potential for deadlock when
mixing these newly scoped providers with singletons already bound
in the injector inside the same application.

This RFE introduces a new method Scopes.asSingleton(Binding) which
takes a binding and returns a singleton-scoped provider backed by
the binding. If the binding is associated with an injector then it
will use the injector's singletonCreationLock. If the binding is
for some reason not associated with an injector then it will use
the binding itself to synchronize creation of the singleton.