link
Avalon
Avalon Central
Home PlanetProductsCentral
Using Merlin
Managing Dependencies - Manual Association

The manual dependencies tutorial covers additional information dealing with the explict control over dependency binding. In this example we have HelloComponent with a dependency on two services of the same type. If we depended on classic merlin auto-assembly we would not necessarily get the desired result. In such a situation, Merlin provides support for overriding the auto assembly process though explicit dependency directives included inside a <component/> tag.

Resources supporting this tutorial are contained in the turorials/dependencies/manual package.

In the block.xml we have three component directives:

     <component name="gloria" class="tutorial.IdentifiableComponent"/>
     <component name="nancy" class="tutorial.IdentifiableComponent"/>

     <component name="hello" class="tutorial.HelloComponent">
       <dependencies>
         <dependency key="primary" source="gloria"/>
         <dependency key="secondary" source="nancy"/>
       </dependencies>
     </component>

The "hello" component has been manually wired together using named components references under a set of directives, thereby overriding Merlin auto-assembly heuristics.

Executing the demo

Build and run the tutorial.

$ maven
$ merlin target\classes -execute
        

In the logging output we see that Merlin has established and and assigned the components we requested based on our directives in the block.xml file.

[INFO   ] (tutorial.nancy): contextualize
[INFO   ] (tutorial.gloria): contextualize
[INFO   ] (tutorial.hello): initialization
[INFO   ] (tutorial.hello): assigned primary: /tutorial/gloria
[INFO   ] (tutorial.hello): assigned secondary: /tutorial/nancy
Advanced Features

This completes the introduction to some of the basic features of the merlin platform. More tutorials will be added so please check for new releases and updates. In the meantime you may want to take a look at some of Merlin's more advanced features.