Well, I still have issues with that because producing a scoped bean does not force those constraints on the used concrete type:
public interface Messager { |
String message(); |
} |
|
public final class MessagerImpl implements Messager { |
private final String message; |
private 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!"); |
}
|
But when we try to apply interceptors via InterceptionFactory, then, all of a sudden the concrete type matters:
@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!")); |
}
|
So here we have 2 different features which requires proxies (scoping & intercepting) but each feature force different constraints on the target type. |