the result of bm.instance().select(MyContext.class).get() will not be the same unless you register a special bean for your context. This is what org.jboss.weld.bootstrap.WeldStartup does in createContexts() method. So you could either follow the way Weld registers context beans or for example hold a MyContext reference on the extension class which registers the context (for each extension, the container must provide a bean with scope @ApplicationScoped and qualifier @Default).
Ok - I do have an extension which registers MyContext, in the BeforeBeanDiscovery event observer. Is that not going to work?
Are you saying that I need to use something like:
contexts.add(new ContextHolder<ApplicationContext>(new ApplicationContextImpl(), ApplicationContext.class, UnboundLiteral.INSTANCE));
from WeldBootstrap? If so, how do I access the "contexts" and ContextHolder from my extension?
But really, isn't that what I'm already doing by adding the context in the observer method?
Also, my context is being registered and is available. I just don't know how to get the right instance at the right time to associate the bean store.
Solved the issue, with direction from Martin on IRC (thanks!)...
In my extension which registers my context, I save the instance and make it globally accessible (singleton pattern). Then, whenever I need to associate/disassociate a bean store with the context I can do it with the global instance.
Tried it and it works. Thanks.