Author: Dan North
Overview
Rico is a container written in Ruby, demonstrating the same Inversion-of-Control principles as the Java Pico Container.
It is primarily a proof of concept at this stage - there is an embarrassingly small amount of actual code but it seems to cover the fundamentals.
The Constructor Injector IoC model depends on the signature of the constructor(s) of an object to identify its dependencies. Ruby does not have static types, so we use a list of keys to represent dependencies, passed in when we register a component.
Basic operation
require 'rico' # the main container
include Rico # so we don't need to use Rico:: everywhere
container = Rico.new
- Register a component with key "one"
container.register "one", Object
- Register a component with dependencies
container.register "two", Complex, [ "one" ]
- Get a component
component = container.component "two" # constructs Object, passes it to Complex - constructor and returns the result
Additional behaviour
Rico has the same multicasting behaviour as Pico - you can call methods on a multicaster object and any registered components that understand the method will have it called. This is useful for lifecycle management.
Next steps
Rico currently doesn't support the same ComponentAdapter model as Pico, which would bring it much more into line. Also we need a sample app or two to demonstrate how it works.
