Method: Needle::Container#register
- Defined in:
- lib/needle/container.rb
#register(name, opts = {}, &callback) ⇒ Object
Register the named service with the container. When the service is requested (with Container#[]), the associated callback will be used to construct it.
This returns the registry that was used to register the service.
Usage:
container.register( :calc, :model=>:prototype ) do |c|
Calc.new( c.operations )
end
136 137 138 139 140 141 142 143 144 |
# File 'lib/needle/container.rb', line 136 def register( name, opts={}, &callback ) raise ArgumentError, "expect block" unless callback name = name.to_s.intern unless name.is_a?( Symbol ) @service_points[ name ] = ServicePoint.new( self, name, @defaults.merge( opts ), &callback ) self end |