-
1. Re: Help implementing a context
mkouba Oct 15, 2013 4:24 AM (in response to dudehook)Hi,
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).
-
2. Re: Help implementing a context
dudehook Oct 15, 2013 10:02 AM (in response to mkouba)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.
-
3. Re: Help implementing a context
dudehook Oct 15, 2013 12:40 PM (in response to dudehook)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.