The first example can be hard if there's nothing to model it after. Created a decorator example you can copy from:
http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/decorators -David On Jun 10, 2011, at 10:49 AM, Ranga S wrote: > Thanks Mark! > > Let me try to describe the example. I would like to implement a POJO CDI > example to start with. It would show some of the concepts and annotations. > Once I have that working, I was thinking about providing examples that show > integration of CDI with EJBs or Servlets or JSF. > > Now, for the POJO CDI step, I have defined some classes that use some common > CDI annotations. Structure shown below: > + Interface A > ++ Class A1 implements A (Default) > ++ Class A2 implements A (Alternative) > + Class B (needs to be injected with an implementation of A) > > However, I am stuck at how to "initialize" the CDI provider (CODI) in my test > so that when I access Class B it should be "available" for me to use. From > your email, it sounds like I should do something like what the > BeanManagerProvider does. > > > > - Ranga > > ________________________________ > From: Mark Struberg <[email protected]> > To: [email protected] > Sent: Friday, June 10, 2011 3:47 AM > Subject: Re: Examples - CDI > > Hi! > >> new WebBeansContext().getBeanManagerImpl().getBeans(MyClass.class) > > You should avoid to use the WebBeansContext manually. And for sure not create > a new instance at all ;) > > I fear I miss the context of what you try to achieve, but I guess you need to > 'start' the CDI container before you can use it. You can take a look at OWBs > cditest project [1]. It contains a container-independent API + an impl for > OWB. > > > If you are hacking against OWB internal stuff (so you skip container > portability) then you could just use BeanManagerImpl.getInstance(). > If you like to keep it portable, then you might use a trick like I wrote in > CODIs BeanManagerProvider [2]. > > LieGrue, > strub > > [1] https://svn.apache.org/repos/asf/openwebbeans/trunk/webbeans-test/ > [2] > https://svn.apache.org/repos/asf/myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/BeanManagerProvider.java > > --- On Thu, 6/9/11, Ranga S <[email protected]> wrote: > >> From: Ranga S <[email protected]> >> Subject: Re: Examples - CDI >> To: "[email protected]" <[email protected]> >> Date: Thursday, June 9, 2011, 11:16 PM >> Thanks! >> I tried > using the createEJBContainer construct, but it >> complains about "not finding any modules to deploy" when I >> run it. >> However, I was trying to use the following, but it prints >> an empty list: >> new >> WebBeansContext().getBeanManagerImpl().getBeans(MyClass.class) >> >> >> >> - Ranga >> >> >> ________________________________ >> From: David Blevins <[email protected]> >> To: [email protected] >> Sent: Wednesday, June 8, 2011 4:03 PM >> Subject: Re: Examples - CDI >> >> >> On Jun 8, 2011, at 3:09 PM, Ranga S wrote: >> >>> Thanks! >>> >>> I wanted to first get a simple stand-alone example up >> and running. I was > wondering how to get access to the OWB >> container to lookup a "Named" bean. If a standalone example >> is out-of-the scope of this project, please let me know and >> I shall look at integrated examples. >> >> Just slipped this in: >> >> https://issues.apache.org/jira/browse/OPENEJB-1571 >> >> Should do the trick! The >> EJBContainer.createEJBContainer() is the best approach for >> our examples. >> >> -David >> >>> >>> ________________________________ >>> From: Mark Struberg <[email protected]> >>> To: [email protected]; >> Ranga S <[email protected]> >>> Sent: Wednesday, June 8, 2011 12:59 PM >>> Subject: Re: Examples - CDI >>> >>> hi! >>> >>> You could look at the maven archetypes for Apache >> MyFaces CODI [1] which is a CDI extension. >>> >>> $> mvn archetype:generate -DarchetypeCatalog=http://myfaces.apache.org >>> >>> It creates a small OWB + MyFaces +CODI based example >> stub. Just add OpenEJB on top (e.g. for the database service >> layer) and you're done ;) >>> >>> LieGrue, >>> strub >>> >>> [1] http://myfaces.apache.org/extensions/cdi/index.html >>> >>> --- On Wed, 6/8/11, Ranga S <[email protected]> >> wrote: >>> >>>> From: Ranga S <[email protected]> >>>> Subject: Re: Examples - CDI >>>> To: "[email protected]" >> <[email protected]> >>>> Date: >>> Wednesday, June 8, 2011, 6:52 PM >>>> Hi >>>> >>>> >>>> I would like to take a crack at coming up with >> some >>>> examples for CDI. Let me read some documentation >> on it. Once >>>> I have something concrete, I shall send a note to >> this >>>> list. >>>> >>>> >>>> - Ranga >>
