It may be necessary at times to manually obtain instances of beans managed by Errai IOC from outside the container managed scope or creating a hard dependency from your bean. Errai IOC provides a simple client-side bean manager for handling these scenarios: org.jboss.errai.ioc.client.container.ClientBeanManager.
As you might expect, you can inject a bean manager instance into any of your managed beans. If you use Errai IOC in its default mode you will need to inject the synchronous bean manager (org.jboss.errai.ioc.client.container.SyncBeanManager).
If you need to access the bean manager outside a managed bean, such as in a unit test, you can access it by calling org.jboss.errai.ioc.client.container.IOC.getBeanManager()
Looking up beans can be done through the use of the lookupBeans() method. Here's a basic example:
In this example we lookup a bean class named SimpleBean. This example will succeed assuming that SimpleBean is unambiguous. If the bean is ambiguous and requires qualification, you can do a qualified lookup like so:
In this example we manually construct instances of qualifier annotations in order to pass it to the bean manager for lookup. This is a necessary step since there's currently no support for annotation literals in Errai client code.
Not all beans that are available for injection are available for lookup from the bean manager by default. Only beans which are explicitly scoped are available for dynamic lookup. This is an intentional feature to keep the size of the generated code down in the browser.