lib/dependency_injection/container.rb in dependency_injection-0.1.1 vs lib/dependency_injection/container.rb in dependency_injection-0.2.0
- old
+ new
@@ -1,6 +1,8 @@
+require 'dependency_injection/alias_definition'
require 'dependency_injection/definition'
+require 'dependency_injection/lazy_definition'
module DependencyInjection
class Container
attr_reader :definitions, :parameters
@@ -17,10 +19,15 @@
if (definition = @definitions[name])
definition.object
end
end
- def register(name, klass_name)
- @definitions[name] = Definition.new(klass_name, self)
+ 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