Używanie CDI w postaci singletonu

Usiłuję wstrzyknąć obiekt programu rejestrującego w klasie, która jest implementowana po podejściu singleton.

Kod wygląda prawie tak:

Logger klasa:

public class LoggerFactory {
    @Produces 
    public Logger getLogger(InjectionPoint caller){
        return Logger.getLogger(caller.getMember().getDeclaringClass().getName());
    }
}

Następnie tworzę klasę, która wymaga programu rejestrującego i implementuje wzorzec Singleton:

public class MySingleton{
    @Inject
    private Logger logger;

    private MySingleton instance;

    /*
     * Private constructor for singleton implementation
     */
    private MySingleton(){
        logger.info("Creating one and only one instance here!");
    }

    public MySingleton getInstance(){

        if(instance == null) {
            instance = new MySingleton();
        }

        return instance;
    }

}

Jeśli uruchomię kod (na Glassfish 3.1.2.2), otrzymam NPE, gdy tylko spróbuję użyć rejestratora. Co robię źle (beans.xml plik jest na miejscu)? Próbowałem również użyć@Inject za pomocą metody ustawiającej dlaLogger obiekt, ale bez szczęścia.

questionAnswers(2)

yourAnswerToTheQuestion