I have not tested this yet, but I believe that it will work. For each custom area / context that you want in your application, you just need to add this context through the extension when initializing the container:
public void afterBeanDiscovery(@Observes AfterBeanDiscover afterBeanDiscovery, BeanManager beanManager) { CustomContext customContext = new CustomContext(); afterBeanDiscovery.addContext(customContext); beanManager ... }
Now, the trick, you need to link to this context, so that later, when you want to start or stop it, you can. It will be something like:
@Inject protected HttpRequestLifecycle httpRequestLifecycle; public void doSomething() { startContext(); doStuff(); stopContext(); } public void startContext() { httpRequestContextLifecycle.getHttpRequestContext().activate(); }
This should do it, there is not a lot of documentation there, so I hope this helps.
Anyone interested, check out the source here: http://github.com/walterjwhite/server.web.application
Walter
Walter white
source share