use of org.apache.deltaspike.core.util.metadata.builder.DelegatingContextualLifecycle in project dolphin-platform by canoo.
the class CdiManagedBeanFactory method createDependentInstance.
@Override
public <T> T createDependentInstance(Class<T> cls) {
Assert.requireNonNull(cls, "cls");
BeanManager bm = BeanManagerProvider.getInstance().getBeanManager();
AnnotatedType annotatedType = bm.createAnnotatedType(cls);
final InjectionTarget<T> injectionTarget = bm.createInjectionTarget(annotatedType);
final Bean<T> bean = new BeanBuilder<T>(bm).beanClass(cls).name(UUID.randomUUID().toString()).scope(Dependent.class).beanLifecycle(new DelegatingContextualLifecycle<T>(injectionTarget)).create();
Class<?> beanClass = bean.getBeanClass();
CreationalContext<T> creationalContext = bm.createCreationalContext(bean);
T instance = (T) bm.getReference(bean, beanClass, creationalContext);
contextMap.put(instance, creationalContext);
beanMap.put(instance, bean);
return instance;
}
Aggregations