After some discussions with Walter White I have added some experimental code to
weld extensions to enable the automatic proxying of interfaces.
To demonstrate how this works, here is a sample:
@AutoProxy(QueryInvocationHandler.class)
public interface QueryService<T> {};
public interface UserQuery extends QueryService<User>
{
@Query("select u from user u where u.username=:1")
public User findUserByUsername(String username);
}
public class QueryInvocationHandler implements InvocationHandler
{
@Inject EntityManager entityManager;
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable
{
//run the query based on the annotations on the method
}
}
Any interface that extends QueryService will be automatically proxied by the
container, using the InvocationHander specified in the @AutoProxy annotation.
This proxy is registered as a bean, and if any qualifiers are present on the
Interface being proxied these are added to the bean. It is also possible to
inject into the InvocationHandler.
I also plan to make @AutoProxy a meta annotation, so the above could also be
represented as:
@AutoProxy(QueryInvocationHandler.class)
public @interface QueryService{}
@QueryService
public interface UserQuery
{
@Query("select u from user u where u.username=:1")
public User findUserByUsername(String username);
}
Does all this sound ok, or does it not have a strong enough use case to include
it in Weld Extensions?
Stuart
_______________________________________________
seam-dev mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/seam-dev