[webbeans-dev] Dynamic lookup

Gavin King gavin at hibernate.org
Sat Dec 6 18:07:20 EST 2008


An issue that Bill brought up on the last concall, and that has been
bothering me for a while is that we have a few different cases where
the application wants to perform a dynamic lookup:

(1) when binding types vary at runtime
(2) when the dependency is optional
(3) when you want to obtain an object that belongs to a child manager

But the only way we let you do this is by injecting the Manager
object, which has really evolved into an SPI-type integration point
and has a whole bundle of operations that should not really be in the
view of the application. Furthermore, it requires use of
AnnotationLiteral for all binding types, which is pretty nasty.

So I think we need to provide a different API, one that is more
appropriate to usage by the application.

Other solutions do have sugar for this: Guice has an injectable
Provider<T> interface, Spring let's you write an abstract method which
is implemented by the container.

I think we should model a lookup interface on what we have for event
firing. Analogous to:

   @Observable @SomeBinding Event<SomeEventType> someEvent;

We should let you inject:

   @Obtainable @SomeBinding Instance<SomeType> someInstance;

Which would let you call someInstance.get() to obtain an instance of
the SomeType with SomeBinding.

This would involve the following new interface:

   public interface Instance<T> {
      public T get(Annotation... bindings);
      public boolean isSatisfied(Annotation... bindings);
   }

This is a *much* simpler API to use.

The isDefined() method would let you determine if any Web Bean exists
that satisfies the API type and bindings.

-- 
Gavin King
gavin.king at gmail.com
http://in.relation.to/Bloggers/Gavin
http://hibernate.org
http://seamframework.org



-- 
Gavin King
gavin.king at gmail.com
http://in.relation.to/Bloggers/Gavin
http://hibernate.org
http://seamframework.org



More information about the weld-dev mailing list