Maybe we could extend WeldInstance functionality instead. WeldInstance.Handler<T> is currently initialized eagerly, i.e. a bean instance is obtained immediately when a handler instance is created. We could introduce a lazy variant of a handler so that it's possible to sort/filter the handlers before use, e.g. something like:
class Bar { |
@Inject |
WeldInstance<Foo> instance; |
|
public void process() { |
instance.lazyHandlers().sort(Bar::compare).findFirst().ifPresent(fooHandler -> fooHandler.get().process()); |
} |
|
static <T> int compare(Handler<T> h1, Handler<T> h2) { |
// comparison logic... e.g. inspecting bean metadata |
} |
}
|
A convenient comparator which considers javax.enterprise.inject.spi.Prioritized and javax.annotation.Priority could be provided. Another use case might be to allow to filter beans before use, e.g. to filter out @Dependent beans. |