Hi,

I'm trying to integrate Guice with JAdapter (http://code.google.com/p/
jadapter), at the same time learning Guice in more depth. However, I'm
getting a little confused. :)

In JAdapter, you write an adapter class like:

  class FooBar implements Foo {
      public FooBar(Bar context) { ... }
      public void foo() {}
  }

The idea is that the single-argument constructor takes the adapted
context (a Bar) and implemented the interface being adapted to (Foo).

In code using the adapter registry, one might @Inject a
TransfomerRegistry, and then do:

   Foo foo = transformerRegistry.transform(bar, Foo.class);

The adapter registry looks up the most appropriate adapter from bar to
a Foo (FooBar.class in this case) and instantiates it.

I'd also like to support @Inject annotations on a FooBar adapter under
Guice, for example with setters or a void wire() type method, so that
when the JAdapter registry instantiates a FooBar, it is injected (from
the default or singleton scope, at least).

My first attempt at this is to define a custom @AdapterScoped scope.
The idea is that people could do:

    // Register adapters
    bind(FooBar.class).in(AdapterScoped.class);

    // Register the adapter registry, which can then be injected into
other classes
    bind(TransformerRegistry.class).to(GuiceAdapterRegistry.class);

I've managed to write the AdapterScoped annotation, and I've read the
docs on custom scopes, but I'm still confused. For example, I don't
understand how/when the SimpleScope is "seeded" (which is not part of
the Scope interface), or whether there's a way to enumerate types in a
scope.

More concretely, the two missing pieces for me are:

 - In GuiceAdapterRegistry's constructor, I'd like to iterate over all
objects in the @AdapterScoped scope, to add them to the internal
JAdapter registry.

 - In the GuiceAdapterRegistry.transform() implementation, I'd then
like to instantiate the FooBar class using Guice (or imperatively ask
Guice to inject the instance just constructed) so that @Inject is
honoured based on the current Guice configuration. This should also
allow classes in the @AdapterScoped scope to be injected with unscoped
instances or instances in the @Singleton scope.

It's possible I'm barking up the wrong tree here, of course. I also
looked at Multibindings, but since I'm effectively registering classes
here and want to inject each time a class is instantiated as the
result of a transform() call, they don't seem to be a match to me.

Any pointers would be greatly appreciated!

Martin

-- 
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.

Reply via email to