User Documentation

One minute description
Two minute tutorial
Five minute introduction
Advanced Topics
FAQ
Container
Components
Terminology
Mock Objects
Inversion of Control Types

Patterns

Inversion of Control 
Dependency Injection 
Constructor Injection 
Setter Injection 
Interface Implementation Separation 
Lifecycle 
Antipatterns

Developer Documentation

 Current build status
How To Contribute
Relative Volunteering
Release Process

Project Information

Slogan
Mailing lists
Source Repositories
Open Issues
Blog entries 
Statistics
Team
Sister Projects
TShirts

Miscellaneous

Differentiators
Nirvana

Full Sitemap

Feeds


Site
News
Rico

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

  1. Register a component with key "one"
    container.register "one", Object
  1. Register a component with dependencies
    container.register "two", Complex, [ "one" ]
  1. Get a component
    component = container.component "two" # constructs Object, passes it to Complex
  2. 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.