Class: Dry::Core::Container

Inherits:
Object
  • Object
show all
Includes:
Constants, Mixin
Defined in:
lib/dry/core/container.rb,
lib/dry/core/container/item.rb,
lib/dry/core/container/stub.rb,
lib/dry/core/container/mixin.rb,
lib/dry/core/container/config.rb,
lib/dry/core/container/registry.rb,
lib/dry/core/container/resolver.rb,
lib/dry/core/container/namespace.rb,
lib/dry/core/container/item/factory.rb,
lib/dry/core/container/configuration.rb,
lib/dry/core/container/item/callable.rb,
lib/dry/core/container/namespace_dsl.rb,
lib/dry/core/container/item/memoizable.rb

Overview

Thread-safe object registry

Examples:


container = Dry::Core::Container.new
container.register(:item, 'item')
container.resolve(:item)
=> 'item'

container.register(:item1, -> { 'item' })
container.resolve(:item1)
=> 'item'

container.register(:item2, -> { 'item' }, call: false)
container.resolve(:item2)
=> #<Proc:0x007f33b169e998@(irb):10 (lambda)>

Defined Under Namespace

Modules: Configuration, Mixin, Stub Classes: Config, Item, Namespace, NamespaceDSL, Registry, Resolver

Constant Summary collapse

Error =
Class.new(StandardError)
KeyError =

Error raised when key is not defined in the registry

Class.new(::KeyError)

Constants included from Constants

Dry::Core::Constants::EMPTY_ARRAY, Dry::Core::Constants::EMPTY_HASH, Dry::Core::Constants::EMPTY_OPTS, Dry::Core::Constants::EMPTY_SET, Dry::Core::Constants::EMPTY_STRING, Dry::Core::Constants::IDENTITY, Dry::Core::Constants::Undefined

Constants included from Mixin

Mixin::PREFIX_NAMESPACE

Method Summary

Methods included from Constants

included

Methods included from Mixin

#[], #_container, #clone, #decorate, #dup, #each, #each_key, #enable_stubs!, extended, #freeze, #import, included, #key?, #keys, #merge, #namespace, #register, #resolve