avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen McConnell <mcconn...@apache.org>
Subject [merlin] constructor injection feature
Date Fri, 12 Mar 2004 09:28:55 GMT

A new binary snapshot of Merlin is now available.  The snapshot includes 
support for the injection of classic avalon lifecycle artifacts via 
constructor (including Logger, Configuration, Parameters, Context, 

There are no constraints imposed concerning the ordering of lifecycle 
artifacts (Logger, Configuration, Parameters, Context, ServiceManager).

However, the following restrictions apply:

   1. If a single multi-argument constructor is declared the activation
      implementation will attempt to populate the constructor relative
      to the set of classic Avalon artifacts.  If the consutuctor cannot
      be fully populated, an exception will be thrown.

   2. If a component class declares multiple constructors then
      in order to remain compliant with framework 4.1 the activation
      implementation will attempt to use a null argument construtor.
      If no null argument constructor is found within the set of
      available public constructors, an exception will be thrown.

In addition to the above - special handling is included for the context 
artifact.  Under the Avalon Meta specification, a component may declare 
that the supplied context is castable to a particular interface. Under 
classic Avalon the object implementing the context argument must by 
definition implement the Avalon Context interface.  In the case of a 
constructor based supply of context - the requirement for the 
implementation of Avalon Context interface is not implied.

Following a period of experimentation I'm planning on taking a closer 
look at the Avalon Framework docs to see what (if any) changes are 
required to support the extended constructor semantics.  My initial 
impression is that represents a change to documentation and no change to 
actual interfaces.  Even so, I have in mind the updating of framework 
documentation to support constructor based injection under a 4.2 
framework release aligned with Avalon Meta 1.4 and Merlin 3.3.  Propsals 
to this effect will be posted to dev@avalon in due corse. In the 
meantime this behaviour should be considered as specific to the Avalon 
Activation framework.

An example the use of constuctor based injection of lifecycle artifacts 
is included below:

  * A widget.
  * @avalon.component name="widget" lifestyle="singleton"
  * @avalon.service type="tutorial.Widget"
public class DefaultWidget implements Widget

     private final Logger c_logger;
     private final Configuration c_config;
     private final Gizmo c_gizmo;

     * Creation of a new widget.
     * @param logger the assigned logging channel
     * @param manager the assigned service manager
     * @param config the assigned configuration
     * @avalon.dependency key="gizmo"
     *    type="tutorial.Gizmo"
     public DefaultWidget (
       Logger logger, ServiceManager manager, Configuration config )
       throws ServiceException
         c_logger = logger;
         c_config = config;
         c_gizmo= (Gizmo) manager.lookup( "gizmo" );

     // plus widget stuff

A binary download is available under:


Cheers, Steve.


| Magic by Merlin                                |
| Production by Avalon                           |
|                                                |
| http://avalon.apache.org/merlin                |
| http://dpml.net/merlin/distributions/latest    |

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

View raw message