Hello everyone,
I am in the process of patching the softwaremill-common CDI extensions [1] from Weld 1.1
to Weld 2.x. I am currently working on their extension for autofactories. I stumbled upon
the following piece of code I would like to migrate:
CurrentInjectionPoint currentInjectionPoint =
Container.instance().services().get(CurrentInjectionPoint.class);
currentInjectionPoint.push(ConstructorInjectionPoint.of(bean,
(WeldConstructor<T>) createdTypeData.getCreatedTypeConstructor()));
instance = newInstance(parameters);
currentInjectionPoint.pop();
Source: [2]
I see how the pop should now be invoked on the `ThreadLocalStackReference` returned by the
push method. I have also found the
InjectionPointFactory#createConstructorInjectionPoint(Bean, Class,
EnhancedAnnotatedConstructor, BeanManagerImpl) method [3]. Now I am wondering how I can
get to the `EnhancedAnnotatedConstructor`, as the approach I am currently using feels
plain wrong.
My code:
CurrentInjectionPoint currentInjectionPoint =
Container.instance().services().get(CurrentInjectionPoint.class);
Class<?> declaringComponentClass = (Class<T>)
createdTypeData.getCreatedTypeConstructor().getBaseType();
BeanManagerImpl manager = ((BeanManagerProxy) beanManager).delegate();
EnhancedAnnotatedConstructor<T> constructor =
(EnhancedAnnotatedConstructor<T>) manager
.createEnhancedAnnotatedType(declaringComponentClass)
.getEnhancedConstructors()
.stream().findAny().get();
ConstructorInjectionPoint<T> actualInjectionPoint =
InjectionPointFactory.instance()
.createConstructorInjectionPoint(bean, declaringComponentClass,
constructor, manager);
ThreadLocalStackReference<InjectionPoint> ref =
currentInjectionPoint.push(actualInjectionPoint);
instance = newInstance(parameters);
My code is also available on Github at [4]. My question is also posted on Stackoverflow
[5], so points will be awarded for the answer.
Thanks in advance!
Jan-Willem Gmelig Meyling
[1]
https://github.com/softwaremill/softwaremill-common/tree/master/softwarem...
<
https://github.com/softwaremill/softwaremill-common/tree/master/softwarem...
[2]
https://github.com/softwaremill/softwaremill-common/blob/master/softwarem...
<
https://github.com/softwaremill/softwaremill-common/blob/master/softwarem...
[3]
http://javadox.com/org.jboss.weld.servlet/weld-servlet/2.3.1.Final/org/jb...
<
http://javadox.com/org.jboss.weld.servlet/weld-servlet/2.3.1.Final/org/jb...
[4]
https://github.com/JWGmeligMeyling/cdi-autofactories/blob/8346cf269d73a8b...
<
https://github.com/JWGmeligMeyling/cdi-autofactories/blob/8346cf269d73a8b...
[5]
http://stackoverflow.com/questions/38436110/proper-way-to-get-enhancedann...
<
http://stackoverflow.com/questions/38436110/proper-way-to-get-enhancedann...