Well, I still have issues with that because producing a scoped bean does not force those constraints on the used concrete type:
{code:java} public interface Messager { String message(); }
public final class MessagerImpl implements Messager { private final String message; private public MessagerImpl(String message) { this.message = message; } public String message() { return message; } }
@Produces @ApplicationScoped public Messager messager() { // this works even though MessagerImpl is not a CDI bean (not proxyable/subclassable) // because only the interface is exposed (and thus proxyable) return new MessagerImpl("hello world!"); } {code}
But when we try to apply interceptors via {{InterceptionFactory}}, then, all of a sudden the concrete type matters:
{code:java} @Produces @ApplicationScoped public Messager messager(InterceptionFactory<Messager> f) { // this does not work because MessageImpl is not proxyable f.configure().add(new AnnotationLiteral<MyIntercepted>() {}); return f.ignoreFinalMethods().createInterceptedInstance(new MessagerImpl("hello world!")); } {code}
So here we have 2 different features which requires proxies (scoping & intercepting) but each feature force forces different constraints on the target type. |
|