RE: [picocontainer-dev] Tiering support 4 Pico
Jörg Schaible <[email protected]>
| Newsgroups | gmane.comp.java.picocontainer.devel |
|---|---|
| Message-ID | <[email protected]> |
It's more or less a AccessCrontollingGuard (compared to the TieringGuard) where you've defined explicitly what types or keys are allowed.
Paul Hammant wrote:
> Jörg,
>
> Can you make a testcase for that ?
>
> - Paul
>
> On Apr 28, 2008, at 12:42 AM, Jörg Schaible wrote:
>
>>
>> Well, this is related to a topic we had on the list before: How to
>> publish components of a contain er explicitly i.e. only published
>> components can be looked up by child containers or directly, while
>> unpublished components can be used for dependency resolution of
>> components within the same container. Maybe we can come up with
>> something that covers both cases.
>>
>> Use case for explicit publishing was always the addition of
>> "modules" with own Pico hierarchies that should not expose internal
>> deps to clients.
>>
>> Paul Hammant wrote:
>>> 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/cont
>>> ainer/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
>>
>>
>>
> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email