Yes. What you want to accomplish is called "injecting into a non-contextual
instance", or in other words "injecting into a non-bean instance". The
object is an injection target.


Here's the basic idea.

1. Obtain the BeanManager
2. Create a CreationalContext, a context that supports the injection process
3. Create an AnnotatedType for the class of the object receiving the
injections
4. Create an InjectionTarget from that AnnotatedType
5. Use InjectionTarget.inject(Object, BeanManager) to satisfy the injection
points on the non-managed object

This operation is performed, amongst other places, in Arquillian's CDI test
enricher. It's how Arquillian takes the test case instance and satisfies
injection points.
https://github.com/arquillian/arquillian/blob/master/testenrichers/cdi/src/main/java/org/jboss/arquillian/testenricher/cdi/CDIInjectionEnricher.java

-Dan

On Wed, Mar 9, 2011 at 15:02, aalmiray <[email protected]> wrote:

> Hi guys,
>
> I wonder if it's possible to offer a set of bean instances (not-managed by
> the container) so that their dependencies are satisfied by the container.
> As
> an example, you can grab a Spring BeanFactory and call autowire on it, like
> this
>
>   app.applicationContext.getAutowireCapableBeanFactory()
>         .autowireBeanProperties(instance,
> AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false)
>
> Is there a similar API in Weld/CDI?
>
> TIA
> Andres
>
> --
> View this message in context:
> http://weld-development-discussions.46994.n3.nabble.com/Offering-beans-post-container-initialization-tp2656992p2656992.html
> Sent from the Weld development discussions mailing list archive at
> Nabble.com.
> _______________________________________________
> weld-dev mailing list
> [email protected]
> https://lists.jboss.org/mailman/listinfo/weld-dev
>



-- 
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597

http://www.google.com/profiles/dan.j.allen#about
http://mojavelinux.com
http://mojavelinux.com/seaminaction
_______________________________________________
weld-dev mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/weld-dev

Reply via email to