RE: [picocontainer-dev] comments on injection
"Putrycz, Erik" <[email protected]>
| Newsgroups | gmane.comp.java.picocontainer.devel |
|---|---|
| Message-ID | <[email protected]> |
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>