[weld-dev] Generic Beans
Stuart Douglas
stuart at baileyroberts.com.au
Tue Mar 2 18:16:48 EST 2010
Ok, I have fixed the test and and committed it. I also changed it so you need an @Inject annotation to inject the configuration annotation. The second case is slightly harder, as you need to do type safe resolution to determine if the bean being injected is a generic bean, however as this occurs in the initialization code there is no guarantee that the bean you are interested in has been installed yet, so you can't just get the bean manager to do the lookup for you.
Stuart
________________________________________
From: Pete Muir [pmuir at redhat.com]
Sent: Tuesday, 2 March 2010 11:45 PM
To: Stuart Douglas
Cc: Weld-Dev
Subject: Re: [weld-dev] Generic Beans
Sorry for the late reply. Got bogged down. Anyway...
Your idea seems about right. I tried out your code, I can't get the test to pass (I get an NPE).
Also, the test case classes don't quite match what I expected. I expected it to look more like:
@Generic(TestAnnotation.class)
public class GenericDep
{
@Inject TestAnnotation data;
public String getValue()
{
return data.value();
}
}
@Generic(TestAnnotation.class)
public class GenericMain
{
@Inject
GenericDep dep;
public String getValue()
{
return dep.getValue();
}
}
I suggest you add this to weld-extensions, we can then work on getting the tests to pass and the syntax fixed. WDYT?
On 22 Jan 2010, at 09:29, Stuart Douglas wrote:
> <generic-extension.zip>
> I have been looking into Gavin's ideas for generic beans, as specified at http://seamframework.org/Weld/PortableExtensionsPackage, and I have come up with a simple prototype. The details of the implementation is as follows:
>
> - All AnnotatedTypes marked @Generic are vetoed and their details stored for later use.
>
> - All beans that have a generic producer field have the details of the Generic annotation value stored
>
> - after bean discovery a new bean is registered for every @Generic annotation type and every instance of the Generic annotation on a producer field. So in the example on the wiki page six beans would be registed, 3 Topics and 3 sessions, one each for 'default', 'prices' and 'deals'. these beans have a synthetic qualifier annotation added to them that only the PE knows about. Also at this point any @InjectGeneric on the annotated type is replaced with @Inject @SyntheticQualifier(value=?) so that generic beans can inject other generic beans.
>
> - The injectionTarget for beans with a generic producer field is wrapped to set the initial value.
>
> The prototype contains a simple test, it contains two generic beans, GenericMain and GenericDep, both are generic on TestAnnotation. GenericDep is injected into GenericMain which is then exposed via a producer field in GenericProducer and injected into InjectedBean. GenericDep injects an instance of TestAnnotation as configuration.
>
> Could someone have a look at this and let me know if this approach is ok? (In order to build it you may need to get the most recent weld-extensions from svn)
>
> Stuart_______________________________________________
> weld-dev mailing list
> weld-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/weld-dev
More information about the weld-dev
mailing list