Module: MinDI

Defined in:
lib/mindi.rb

Overview

:nodoc:

Defined Under Namespace

Modules: BasicContainer, Container, Injectable, InjectableContainer

Constant Summary collapse

VERSION =

Extend a class (or module) with Container to make the class behave as a class of service containers. Containers encapsulate the way in which related services are instantiated and connected together. Services themselves are insulated from this process [except when they are injected with the container].

Use MinDI by includeing the MinDI::InjectableContainer module in your container class. As of version 0.2, this does two things: it extends your container class with the Container module, which provides class methods for expressing service definitions in a natural, rubylike way. It also injects the container into all services which gives them direct access to the other services in the container. If you prefer to have the container funtionality without injecting services (i.e., just “contructor injection”) You can just include MinDI::BasicContainer.

The Container module also defines shortcuts for defining some service types using method_missing. These methods and shortcuts are described below.

A service definition involves a service name and a block of code. It defines an instance method whose name is the service name. The block is used to instantiate the service. When and how that service is instantiated depends on the type of service.

Note: MinDI uses some instance variables and auxiliary instance methods in the container. The instance variables have the same name as the corresponding services, possibly with added suffixes, as in the case of #deferred. The auxiliary methods are named so as to make conflicts unlikely. See the implemetations of #iv and #impl_method_name for details.

Note that services can be defined dynamically by reopening the class scope or simply by calling the service with a block. See examples/dynamic.rb.

'0.5'