[picocontainer-dev] Tiering support 4 Pico
Paul Hammant <[email protected]>
| Newsgroups | gmane.comp.java.picocontainer.devel |
|---|---|
| Message-ID | <[email protected]> |
I've shoved in a new class org.picocontainer.containers.TieringGuard
(subject to rename).
And there's a testcase at the bottom of DPCTC ( http://svn.codehaus.org/picocontainer/java/2.x/trunk/pico/container/src/test/org/picocontainer/DefaultPicoContainerTestCase.java
)
public static class Couch {
}
public static class TiredPerson {
private Couch couchToSitOn;
public TiredPerson(Couch couchToSitOn) {
this.couchToSitOn = couchToSitOn;
}
}
@Test public void
testThatParentTraversalForComponentsCanBeBlocked() {
DefaultPicoContainer grandparent = new DefaultPicoContainer();
DefaultPicoContainer parent = (DefaultPicoContainer)
grandparent.makeChildContainer();
parent.setTiering(true);
DefaultPicoContainer child = (DefaultPicoContainer)
parent.makeChildContainer();
child.setTiering(true);
grandparent.addComponent(Couch.class);
child.addComponent(TiredPerson.class);
TiredPerson tp = null;
try {
tp = child.getComponent(TiredPerson.class);
fail("should have barfed");
} catch (AbstractInjector.UnsatisfiableDependenciesException
e) {
System.out.println("");
// expected
}
}
The idea is that in a tiered application, you should only depend on
the classes from the immediate tier below you.
Thus DPC now has a setTiering(boolean) method (subject to rename).
TieringGuard uses a static ThreadLocal to indicate to parents that
we're traversing towards the root of the container tree to fill deps.
Comments appreciated.
- Paul
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email