Sha256: 768adb17e6f4470c33c1a9d68f272f1fdc2a46c1259e2cb59d2bb7e5e1a0615b

Contents?: true

Size: 872 Bytes

Versions: 4

Compression:

Stored size: 872 Bytes

Contents

require 'dependency_injection/alias_definition'
require 'dependency_injection/definition'
require 'dependency_injection/lazy_definition'

module DependencyInjection
  class Container
    attr_reader :definitions, :parameters

    def initialize
      @definitions = {}
      @parameters  = {}
    end

    def add_parameter(name, value)
      @parameters[name] = value
    end

    def find(name)
      @definitions[name]
    end

    def get(name)
      if (definition = self.find(name))
        definition.object
      end
    end

    def register(name, klass_name, lazy=false)
      definition = lazy ? LazyDefinition.new(klass_name, self) : Definition.new(klass_name, self)
      @definitions[name] = definition
    end

    def register_alias(name, alias_definition_name)
      @definitions[name] = AliasDefinition.new(alias_definition_name, self)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dependency_injection-0.4.3 lib/dependency_injection/container.rb
dependency_injection-0.4.2 lib/dependency_injection/container.rb
dependency_injection-0.4.1 lib/dependency_injection/container.rb
dependency_injection-0.4.0 lib/dependency_injection/container.rb