[
https://jira.jboss.org/browse/WELD-555?page=com.atlassian.jira.plugin.sys...
]
Kabir Khan commented on WELD-555:
---------------------------------
I pasted in the wrong email in the description. Hopefully it will make more sense now :-)
Basically, I want to use InjectionServices to inject beans that don't exist in the
BeanManager from some external source such as the MC. This currently fails at the
validation stage since the validator does not support external lookups. Also, I don't
see a way in what is made available by InjectionContext to determine which injection
points have been injected and which have not.
If I have the following installed in Weld:
class Bean
{
@Inject WeldDependency wd;
@Inject ExternalDependency ed;
}
@Default
class WeldDependency
{
}
And in some external source:
class ExternalDependency
{
}
This will fail in validation. Also it would be good to be able figure out in
InjectionServices, after the call to ctx.proceed(), that Weld has injected the
'wd' dependency so my InjectionServices only needs to look up the 'ed'
field.
Pluggable validation
--------------------
Key: WELD-555
URL:
https://jira.jboss.org/browse/WELD-555
Project: Weld
Issue Type: Feature Request
Components: Weld SPI
Reporter: Kabir Khan
From Weld Dev mailing list:
--------------------------------------------
That's tricky. I'm sort of having the same problem with Spring integration.
Bean Validation requires a matching bean to exist so the only idea I can come up with is
to register a placeholder before injection actually takes place. But that defeats the
purpose of having an InjectionService (what's the use for it if you can do the same
via a custom bean).
One potential solution that I see is to allow for a ValidationService in a similar vein
to InjectionService.
On 10-06-11 11:18 AM, Kabir Khan wrote:
The Weld/MC integration currently works via a "push" model where the MC pushes
beans with the @WeldEnabled annotation so that they are usable from Weld. If I have this
MC bean
@Thing
@WeldEnabled
public class ThingBean
{
}
and this Weld bean
public class ThingField
{
@Inject @Thing
public ThingBean thing;
}
Then when deployed the MC bean is made available to Weld. I do something along the lines
of
---
//Set up Weld
TestContainer testContainer = new TestContainer(new MockEELifecycle(),
Arrays.asList(McBeanObserver.class, ThingBean.class), null);
testContainer.getDeployment().getServices().add(InjectionServices.class, new
McLookupInjectionServices()); //Adding custom injection services
testContainer.getLifecycle().initialize();
//Deploy MC bean
...
//Start up Weld
testContainer.getLifecycle().beginApplication(); //A
testContainer.ensureRequestActive();
//Get bean
Set<Bean<?>> beans = getCurrentManager().getBeans(clazz);
assertEquals(1, beans.size());
Bean<ThingBean> bean = (Bean<ThingBean>)beans.iterator().next();
CreationalContext<T> createCtx =
getCurrentManager().createCreationalContext(null);
ThingBean bean = bean.create(createCtx); //B
---
This works fine. My McLookupInjectionServices bean just does some simple logging while
playing around
public class McLookupInjectionServices implements InjectionServices
{
public<T> void aroundInject(InjectionContext<T> ctx)
{
System.out.println("--------> CUSTOM INJECTION SERVICES");
ctx.proceed();
}
public void cleanup()
{
}
}
and I can see it kicking in as a result of the call to B.
What I would like to do is to change what I have done so that instead of having to know
in advance which MC beans should be made available to Weld, to use my
McLookupInjectionServices to "pull" any beans it can not find in Weld from the
Microcontainer instead. My initial attempt at this is to get rid of the @WeldEnabled
annotation from the MC bean:
@Thing
@WeldEnabled
public class ThingBean
{
}
However, this falls at A, and never gets to my McLookupInjectionServices
org.jboss.weld.DeploymentException: Injection point has unstatisfied dependencies.
Injection point: field org.jboss.test.kernel.weld.mctowb.support.wb.ThingField.thing;
Qualifiers: [@org.jboss.test.kernel.weld.mctowb.support.mc.Thing()]
at org.jboss.weld.Validator.validateInjectionPoint(Validator.java:232)
at org.jboss.weld.Validator.validateBean(Validator.java:80)
at org.jboss.weld.Validator.validateRIBean(Validator.java:100)
at org.jboss.weld.Validator.validateBeans(Validator.java:282)
at org.jboss.weld.Validator.validateDeployment(Validator.java:268)
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:389)
at
org.jboss.weld.mock.MockServletLifecycle.beginApplication(MockServletLifecycle.java:105)
This ends up in TypeSafeResolver
public Set<T> resolve(Resolvable key)
{
final MatchingResolvable resolvable = MatchingResolvable.of(transform(key));
Callable<Set<T>> callable = new Callable<Set<T>>()
{
public Set<T> call() throws Exception
{
return sortResult(filterResult(findMatching(resolvable)));
}
};
Set<T> beans = resolved.putIfAbsent(resolvable, callable);
return Collections.unmodifiableSet(beans);
}
but I don't see any way to make this pluggable so that it can check the MC? Is there
such functionality, and if not would it be possible to add it? The idea being that I could
do
public<T> void aroundInject(InjectionContext<T> ctx)
{
System.out.println("--------> CUSTOM INJECTION SERVICES");
ctx.proceed();
//Iterate over ctx.getInjectionTarget().getInjectionPoints() and find the unresolved
ones
}
Although, I don't know if there is anything there to see if an injection point has
been injected either?
Cheers,
Kabir
_______________________________________________
weld-dev mailing list
weld-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/weld-dev
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira