LightWire XML Configuration Update: Now Supporting Init-method and Mixin

2007 June 27
tags: ColdFusion · LightWire · XML
by Paul Marcotte
When I realized my concept for a ServiceLocator fell in the category of "interesting patterns you'll never use", I decided instead to work in a <mixin/> tag for LightWire. The tag is a child of <bean/> like <constructor-arg/> or <property/>. Children of <mixin/> <value/>, <ref/>, <map/>, or <bean/> defined therein will be "mixed in" rather than constructor or setter injected.Here is a quick snippet of the use of <mixin/> in your XML. <bean id="AdminGateway" class="model.admin.AdminGateway">
      <constructor-arg name="dsn"><value>${dsn}</value></constructor-arg>
   </bean>
   <bean id="AdminService" class="model.admin.AdminService">
      <constructor-arg name="AdminGateway">
         <ref bean="AdminGateway"/>
      </constructor-arg>
   </bean>
   <bean id="AdminController" class="controller.AdminController">
      <mixin name="AdminService">
         <ref bean="AdminService"/>
      </mixin>
   </bean>
In the example above, AdminGateway and AdminService have constructor-arg dependencies defined and AdminController has a mixin dependency for AdminService. You would typically only use a mixin to inject a dependency where a using constructor-arg would create a circular dependency, so this example is purely illustrative. In addition to the mixin tag, the init-method attribute of a bean tag is now also supported. Check out the enclosed document for a breakdown of the tags and attributes that LightWire supports. If you use LightWire for mixins, but prefer to use XML to define your beans, you can check out the latest source from http://svn.riaforge.org/lightwire/trunk.