Generally speaking, no. I've implemented what you described by using a custom Provider that maintains a map of Key => instance. This also involved understanding the bindings (so that the custom Provider would be used to create the serializable instances), and making sure that all required dependent bindings were available at the other end of the wire.
Fred On Mon, Jun 4, 2012 at 2:33 PM, glenviewjeff <[email protected]> wrote: > I would like to a class to request an instance of the key used to bind the > object itself. I believe I need to do this to support serialization so > that I grab the correctly bound object upon reconstruction. > > I thought this would work if I did something like the following: > > class Foo { > @Inject Foo(Key<Foo> fooKey) {} > } > > But I got a binding error: > > Error injecting constructor, java.lang.RuntimeException: Missing type > parameter. > > Is this possible, or would I have to make a custom provider that uses a > setter to set they key after the object is instantiated? > > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/google-guice/-/Cm0sGg1tP1MJ. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/google-guice?hl=en. > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
