Em Sun, 20 Dec 2009 18:30:29 -0200, Piero Sartini <[email protected]>
escreveu:
Ok.. I played around with this some more. First of all its interesting
that CDI does not need
to be instantiated. Only thing neccessary is an empty beans.xml in
META-INF/ and a JSR-299 aware
container... this may also be our sweet jetty + 3 jars.
Nice!
For CDI, everything is a potential bean. Any interface with available
implementation may become a managed bean and its dependencies
are resolved. This has some implications:
* If @javax.inject.Inject is found on any class (including
tapestry managed), CDI tries to do its work. It may be successfull,
but because of tapestry's instance pooling and re-use this is not very
useful. Or do I miss something?
CDI should not mess with Tapestry-controlled classes at all. They're not
meant to be injected in other objects and Tapestry-IoC already takes care
of dependency injection.
Isn't there any way to prevent packages from being touched by CDI? In Weld?
* implementing JSR-330 alone could be dangerous, because in this
case two IoC containers will try to handle the same annotation as soon
as the beans.xml file is present.
Implementing JSR-330, to me, equals to make Tapestry implement JSR 330
itself, not using any other container to do that.
Of course, if you split out the CDI beans into their own jar,
everything is fine (just provide the beans.xml file there and not in
the webapp).
This is far from ideal, as we would need to package the classes before
running or testing the application.
In my understanding we need to go over the tapestry
MasterObjectProvider to be able to inject the beans then. Where I am
now is that I contribute an ObjectProvider which queries CDI for the
objectType and returns it if successfull. This seems to work.
Have you looked at how the Spring integration is implemented?
Problem is that this code throws a ClassCastException:
public <T> T provide(Class<T> objectType, AnnotationProvider
annotationProvider, ObjectLocator locator) {
// ... CDI code ...
return objectType.cast(bean);
(Debug code:
INFO: Object Type: interface sessionbeans.TestBean
INFO: Bean:
org.jboss.weld.bean-/home/ps/projects/sandbox/tapestry-yaml/target/tapestry-yaml/-ManagedBean-class
sessionbeans.TestBeanImpl
INFO: [ERROR] ioc.Registry java.lang.ClassCastException
Have you tried a try/catch block around return objectType.cast(bean)? This
should provide a better error message.
but this code does not throw the exception:
return (T) bean;
Java generics, in this case, does nothing.
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da
Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]