Re: [picocontainer-dev] comments on injection

Paul Hammant <[email protected]>
Newsgroups gmane.comp.java.picocontainer.devel
Message-ID <[email protected]>
Erik

I've thought about this since you penned it.

Inversion of Control suggests that control is good ( in a certain  
direction).  getComponent(..) returning instances for formerly  
unregistered components is bad for mutiple reasons:

   1) you've lost the explicit registration step, meaning the audit  
of what's being used is not clear
   2) there recursive nature of deps ( Apple needs Banana needs  
Orange ) can not adequately tell which constructor to use.  Should it  
aim at the simplest (no args) or the greediest as a strategy?
   3) mixing of DI types.  if a Annotation DI Apple needs Banana or  
Orange, should they be the same injection type? or same with a  
fallback of CDI ?

Finally,

The whole thing is doable without ComponentLocator changes  :

public class MagicLocatingPicoContainer extends DefaultPicoContainer {
   // ctors ..
   public Object getComponent(Object key) {
      Object inst = super.getComponent(key);
      if (inst == null) {
          addComponent(key);
          return super.getComponent(key)
      } else {
         return inst;
      }
   }
}

Thoughts?

- Paul


On Jun 1, 2007, at 1:46 PM, Putrycz, Erik wrote:

> Here is another expanded testcase and more doc.
>
>
> Erik.
>
> From: Paul Hammant [mailto:[email protected]]
> Sent: June 1, 2007 16:20
> To: dev-qxt/[email protected]
> Subject: Re: [picocontainer-dev] comments on injection
>
>
> Expand that a little more with testcode will ya Erik?
>
>
> -ph
>
>
> On Jun 1, 2007, at 11:21 AM, Putrycz, Erik wrote:
>
>
>
>
> My other (main) use case is injection…
>
> When I have
>
> @Inject
>
> private MyClass _myClass;
>
>
> If MyClass is not registered then it gets registered automatically  
> in Pico. With this feature, I hardly have any “initialization” code  
> in my projects. I just start my project by creating a container and  
> everything else gets wired automatically. I’m not sure how this  
> could work out with “getInstance”.
>
>
> Erik.
>
> From: Paul Hammant [mailto:[email protected]]
> Sent: June 1, 2007 13:27
> To: dev-qxt/[email protected]
> Subject: Re: [picocontainer-dev] comments on injection
>
>
> What other usecase is there Erik ?
>
>
> For the one you;ve given :-
>
>
> +          @Test
>
> +          public void testDynamicRegistration() {
>
> +                      MutablePicoContainer pico = new  
> DefaultPicoContainer();
>
> +                      ComponentLocator dynamicReg = new  
> DynamicRegistrationLocator();
>
> +                      pico.addLocator(dynamicReg);
>
> +                      LinkedList<String> list = pico.getComponent 
> (LinkedList.class);
>
> +                      assertNotNull(list);
>
> +          }
>
>
>
> I might prefer ..
>
>
> +          @Test
>
> +          public void testDynamicRegistration() {
>
> +                      MutablePicoContainer pico = new  
> DefaultPicoContainer();
>
> +                      LinkedList<String> list = pico.addComponent 
> (LinkedList.class).getInstance();  // getInstance() is new and  
> implicitly on the last component added ~  v easy to implement
>
> +                      assertNotNull(list);
>
> +          }
>
>
> I know you have a 'bigger' use of your way up your sleeve :-)
>
>
> - Paul
>
>
> On Jun 1, 2007, at 9:46 AM, Putrycz, Erik wrote:
>
>
> <Pico2-locator.patch>
>
>
>
>
>
>
> <Pico2-locator.patch>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.