avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leo Simons <leosim...@apache.org>
Subject Re: IOC policies
Date Wed, 05 Feb 2003 09:17:02 GMT
Daniel Krieg wrote:
> I am attempting to implement my own Container and have some questions
> about Inversion of Control patterns.  I am attempting to create a
> Container that manages a single component type at a time.  The
> contained components may be associated with other components held
> within other container instances.  The Container should be
> responsible for resolving these dependencies within the
> ServiceManager for the component.  Correct so far?


> Now, the Container is also a component with associations to other
> components.  Is it violating IOC if the Container-associated
> components are made available to the child components not within the
> ServiceManager but within the Context? 


> After all, the
> Container-associated components are implicit services to the
> Contained components and therefore should not need to be declared as
> a dependency.

what is an "implicit service"? It is often more transparent, and easier 
wrt reuse, if your components have no "implicit dependencies". If you 
need maximum cross-container reuse, it's best to declare the component 
its dependencies on the container-provided services, and then provide no 
implementation of those services (as the container already does). You 
could also design things so that these services are also declared, but 
using a special mechanism:

         <service role="bla" class="com.foo.bla" implicit="true"/>

> What this really means that a child Context has indirect access to
> the contents of its parent's ServiceManager.  Does this seem
> reasonable or am I missing the boat somewhere?

perfectly reasonable.

> I think a component's ServiceManager should only provide peer
> relationships and components related to a component's Container
> should be part of a component's Context.

this is a point of potential disagreement :D. My preference is to have 
the ServiceManager implementation delegate to the parent (container) its 
servicemanager. IOW:

class MyContainer
     ServiceManager m_sm;

     // ...

     service( ServiceManager sm ) { m_sm = sm; }
         Object somecomponent = /* ... */;
         MyServiceManager sm = new MyServiceManager( m_sm );
         sm.put( /* ... */ );
         somecomponent.service( sm );

     // ...
class MyServiceManager
     ServiceManager m_parent;

     // ...

     MyServiceManager( ServiceManager parent )
         m_parent = parent;
     boolean has( String role )
             return true;

         if(m_parent == null)
             return false;

         return m_parent.has(role);

     // ...

> Any thoughts?

that's the two basic options you have (context or servicemanager) I 
think. Oh, you can also do both, or something more complex :)

Note this in itself hasn't got too much todo with the IoC pattern, it's 
mare a case of which avalon lifecycle interface to use.


- Leo

To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org

View raw message