All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arch.cdi.CdiUtils Maven / Gradle / Ivy

There is a newer version: 18.12.0
Show newest version
package com.arch.cdi;

import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.CDI;

/**
 * Created by wagner.araujo on 09/03/16.
 */
public final class CdiUtils {

//    private static BeanManager beanManager;

    private CdiUtils() {
        //
    }

//    static {
//        try {
//            InitialContext initialContext = new InitialContext();
//            beanManager = (BeanManager) initialContext.lookup("java:comp/BeanManager");
//        } catch (NamingException e) {
//            LogUtils.generate(e);
//        }
//    }

    @Deprecated
    public static BeanManager getBeanManager() {
        return CDI.current().getBeanManager();
    }

    @Deprecated
    public static  T getInstanceReference(Class clazz) {
//        Bean bean = (Bean) beanManager.resolve(beanManager.getBeans(clazz));
//        return beanManager.getContext(bean.getScope()).get(bean, beanManager.createCreationalContext(bean));
        return CDI.current().select(clazz).get();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy