Search in sources :

Example 1 with DelegatingContextualLifecycle

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;
}
Also used : DelegatingContextualLifecycle(org.apache.deltaspike.core.util.metadata.builder.DelegatingContextualLifecycle) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) BeanManager(javax.enterprise.inject.spi.BeanManager)

Aggregations

AnnotatedType (javax.enterprise.inject.spi.AnnotatedType)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 DelegatingContextualLifecycle (org.apache.deltaspike.core.util.metadata.builder.DelegatingContextualLifecycle)1