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