[picocontainer-scm] [jira] (PICO-388) Multiple types of injection with @Inject annotation
"Michael Rimov (JIRA)" <jira-yCVjj/[email protected]> Sat, 7 Jul 2012 16:05:21 -0500 (CDT)
| Newsgroups | gmane.comp.java.picocontainer.cvs |
|---|---|
| Message-ID | <464975742.22703.1341695121280.JavaMail.j2ee-jira@codehaus01.managed.contegix.com> |
Michael Rimov
created PICO-388
Multiple types of injection with @Inject annotation
Issue Type:
Bug
Affects Versions:
3.0
Assignee:
Paul Hammant
Components:
PicoContainer (Java)
Created:
07/Jul/12 4:03 PM
Description:
Discussed here:
http://article.gmane.org/gmane.comp.java.picocontainer.user/1293/match=inject
and other places in the mailing list.
@Test
public void testComponentCanUseConstructorAndAtInjectWithoutAnInitMethod() {
final MutablePicoContainer pico = new DefaultPicoContainer();
pico.addComponent(Carrot.class)
.addComponent(Cheese.class)
.addComponent(Mixer.class);
// fails with org.picocontainer.PicoCompositionException: java.lang.NoSuchMethodException: ...$Mixer.<init>()
final Utensil u = pico.getComponent(Utensil.class);
assertEquals("Mixing carrot with some cheese", u.use());
}
public static final class Cheese {
}
public static final class Carrot {
}
public static interface Utensil {
String use();
}
public static class Spoon implements Utensil {
public String use() {
return "there is no spoon";
}
}
public static class Mixer implements Utensil {
private final Cheese cheese;
@Inject
private Carrot veg;
public Mixer(Cheese cheese) {
this.cheese = cheese;
}
public String use() {
return "Mixing " + simpleClassNameOrNull(veg) + " with some " + simpleClassNameOrNull(cheese);
}
}
private static String simpleClassNameOrNull(Object o) {
return o == null ? null : o.getClass().getSimpleName().toLowerCase();
}
Fix Versions:
3.0
Project:
PicoContainer
Priority:
Major
Reporter:
Michael Rimov
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators .
For more information on JIRA, see: http://www.atlassian.com/software/jira
----------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email