[cdi-dev] @New and producer methods/fields

Mark Struberg struberg at yahoo.de
Sat Sep 24 06:35:56 EDT 2011


Hi folks!

We recently talked about ways to properly destroy beans which got created via Instance or @New.
I just realized that only having 
@Inject @New MyClass dings; 
might not be enough. 

Imagine you have 2 producer methods which create EntityManagers 

public class EntityManagerProducer {   
    @Produces @RequestScoped @UserDb
    public void createUserDbEm() {
        return entityManagerFactory.createEntityManager("userdb");
    }     
    
    @Produces @RequestScoped @AdminDb
    public void createAdminDbEm() {
        return entityManagerFactory.createEntityManager("admindb");
    }     
}

If I need a 'temporarily self managed' userdb EntityManager, I cannot just
type 
@Inject @New @UserDb EntityManager userDbEm;
because according to the spec there is only 1 Bean with exactly @New (and none with additional @UserDb)
The @New is basically useless for producer methods, isn't?

Do we like to address this somehow?

LieGrie,
strub




More information about the cdi-dev mailing list