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