You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Daniel Krieg <dk...@kc.rr.com> on 2003/02/05 08:26:34 UTC
IOC policies
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 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?
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.
Any thoughts?
Re: IOC policies
Posted by Daniel Krieg <dk...@kc.rr.com>.
> As I was thinking through all of this, and recalling previous list
> discussions (Context vs. ServiceManager) I thought of something
interesting.
> When I first started working with Avalon, I was under the assumption that
> ServiceManger was itself a Container that controlled the lifecycle of
> referenced service...not so I think. If the ServiceManager only manages
> access to peer-based components with which a component is associated,
would
> it not "AssociationManager" be a more appropriate name? Its role is
clearly
> that of a "reference resolver" rather than "managing the service".
And to followup, there could be...
public interface Associable {
public void associate(AssociationManager manager)
throws AssociationException;
}
...as a replacement for the (somewhat misnomer) ServiceManager.
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
Re: IOC policies
Posted by Daniel Krieg <dk...@kc.rr.com>.
> > 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:
As far as I know, the current Avalon containers (except maybe EOB) do not
enable declarative services. Say I have an Account component with a
transfer( ) method. With the current Avalon containers, as a component
developer I would need to code the following...
public void transfer(Account to, double amount) {
SecurityManager sm = (SecurityManager)
manager.lookup(SecurityManager.ROLE);
if(sm.isUserInRole("AccountOwner") {
TransactionManager tm = (TransactionManager)
manager.lookup(TransactionManager.ROLE);
tm.begin();
account.deposit(amount);
this.withdraw(amount);
tm.commit();
manager.release(tm);
sm.release(sm);
}
}
However, if I could annotate these requirements in XML config, the Container
could pre- and post-process the request (assuming it controlled access to
intenal components) making the method...
public void transfer(Account to, double amount) {
account.deposit(amount);
this.withdraw(amount);
}
}
much like EJB offers...without actually being EJB. With a Container of this
sort, we could use it to host any type of component whether it be a web
component (servlet), a Swing component, or a distributed middleware
component. The Container would not need to be subclassed or rewritten, just
configured via XML to ensure internal components would have needed pre- and
post-request processing services available (using Interceptors to do the
actual work).
> > 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:
First, ServiceManger exposes the hasService( ) method, implying that a
service may not be present...the component developer forgot to declare a
dependency.
Context has no such implication. Since the Container is providing the
service for its subcomponents, the presents of these services is implied.
Furthermore, since the Container provider (person who configures the
container component) may not also be the Component developer, there may be
discrepencies in the naming of the Container-provided services. The
Component developer can use a logical name which can be mapped to the
Container's actual service name and retrieve the desired service (if
necessary) from Context. If you were using hierarchical ServiceMangers, the
component would be required to know and use the same name as the Container
(violation of SOC?) in order to access (if necessary) the services of the
Container.
As I was thinking through all of this, and recalling previous list
discussions (Context vs. ServiceManager) I thought of something interesting.
When I first started working with Avalon, I was under the assumption that
ServiceManger was itself a Container that controlled the lifecycle of
referenced service...not so I think. If the ServiceManager only manages
access to peer-based components with which a component is associated, would
it not "AssociationManager" be a more appropriate name? Its role is clearly
that of a "reference resolver" rather than "managing the service".
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
Re: IOC policies
Posted by Leo Simons <le...@apache.org>.
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: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
Re: IOC policies
Posted by Peter Donald <pe...@realityforge.org>.
On Wed, 5 Feb 2003 18:26, Daniel Krieg wrote:
> 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.
>
> Any thoughts?
Thats the way I design things.
--
Cheers,
Peter Donald
*------------------------------------------------------*
| Despite your efforts to be a romantic hero, you will |
| gradually evolve into a postmodern plot device. |
*------------------------------------------------------*
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
Re: IOC policies
Posted by Stephen McConnell <mc...@apache.org>.
Leo Sutic wrote:
>
>
>>From: Berin Loritsch [mailto:bloritsch@apache.org]
>>
>>Are you saying that you have a Component that implements the
>>"Containment" pattern (as I dubbed it), meaning that you have
>>developed a component that also happens to be a container?
>>
>>
>
>I have though about this, and basically come up with one little
>issue: We have so far assumed that service dependencies can be
>declared at a Type level - i.e. it is a property of the component
>itself, and not something that is configurable.
>
>
A container can be a type of component - i.e. deps can be configured.
>However, if the component is a container, the sub-components
>inside it may have dependencies that cannot be satisfied by
>sub-components but must be provided to the container-component
>by its container.
>
>This use case, where the dependencies of a component is determined
>by the components inside it, isn't accounted for.
>
>
Checkout the Merlin notion of a Block .. it handles the notion of
container as component, depedencies that the container type has on its
own deployment, management of the assembly of components it contains,
and will shortly provide dynamic exposure of services under its role as
a component.
Cheers, Steve.
--
Stephen J. McConnell
mailto:mcconnell@apache.org
http://www.osm.net
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
RE: IOC policies
Posted by Leo Sutic <le...@inspireinfrastructure.com>.
> From: Berin Loritsch [mailto:bloritsch@apache.org]
>
> Are you saying that you have a Component that implements the
> "Containment" pattern (as I dubbed it), meaning that you have
> developed a component that also happens to be a container?
I have though about this, and basically come up with one little
issue: We have so far assumed that service dependencies can be
declared at a Type level - i.e. it is a property of the component
itself, and not something that is configurable.
However, if the component is a container, the sub-components
inside it may have dependencies that cannot be satisfied by
sub-components but must be provided to the container-component
by its container.
This use case, where the dependencies of a component is determined
by the components inside it, isn't accounted for.
One solution is to subclass the container class and add deps
to the subclass.
/LS
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
Re: IOC policies
Posted by Berin Loritsch <bl...@apache.org>.
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?
Correct.
>
> 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.
Are you saying that you have a Component that implements the
"Containment" pattern (as I dubbed it), meaning that you have
developed a component that also happens to be a container?
Stricly speaking with IOC, as long as the Container provides and
manages all the resources made available to the component, then
you are implementing it correctly. If the resource being made
available is from a container's container, then it is still IOC.
However, it is not a clean use of the Context object to pass
references to components. While we can't tell you not to do it,
the ServiceManager was made for that purpose.
>
> 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?
You can do that with the ServiceManager as well. One of the contracts
with ServiceManager is that they can be hierarchical.
>
> 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.
Nope. Not necessarily. A ServiceManager is allowed to defer
component lookups to a parent container, thus preserving IOC and
the contracts surrounding where to get your components.
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
Re: IOC policies
Posted by Stephen McConnell <mc...@apache.org>.
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?
>
>
If I understand you corectly, I think your describing something close to
the notion of a component "handler"(Fortress) or "appliance" (Merlin).
Service resolution by a ServiceManager implementation is one approach to
depedency resolution (this is basically what the Fortress system does).
>Now, the Container is also a component with associations to other components.
>
Yep.
>Is it violating IOC if the Container-associated components are made available to the child components not within the ServiceManager but within the Context?
>
No, it's not an IOC violation. The ServiceManager and Context are simply
artifacts provided by a container to a component (i.e. the vehicle
through which the resources are provided).
>After all, the Container-associated components are implicit services to the Contained components and therefore should not need to be declared as a dependency.
>
>
In general I disagree with the above. Container associated components
are the concern of the container and that does not imply that they are a
concern of a particular component. If you choose not to declare the
dependency, then in effect, you are defining components that make
explicit assumptions about their containment environment. This leads to
non-portable components.
>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?
>
>
It is reasonable providing you keep in mind that this is implicitly
limiting your components to that containment policy.
>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 consistent with the A4 notions of context and service
separation. Under my own implementation components I've largely stopped
using ServiceManager and Context separation in favor for a single
locator abstraction. The reason being the distinction between what is a
context and what is a service is largely artificial and driven by
implementation concerns. Eliminating this destination results in reduced
code and higher flexibility in the component design.
Cheers, Steve.
--
Stephen J. McConnell
mailto:mcconnell@apache.org
http://www.osm.net
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org