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?
yep.

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?
nope.

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:

mycontainer-config.xml
----------------------
<config>
<services>
<service role="bla" class="com.foo.bla" implicit="true"/>
</services>
</config>

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; }
somewhere()
{
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 )
{
if(myhasmap.contains(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.

cheers,

- Leo



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to