diff --git a/dry-container.gemspec b/dry-container.gemspec index 015cbbc..6032132 100644 --- a/dry-container.gemspec +++ b/dry-container.gemspec @@ -30,7 +30,6 @@ Gem::Specification.new do |spec| # to update dependencies edit project.yml spec.add_runtime_dependency "concurrent-ruby", "~> 1.0" - spec.add_runtime_dependency "dry-configurable", "~> 0.13", ">= 0.13.0" spec.add_development_dependency "bundler" spec.add_development_dependency "rake" diff --git a/lib/dry/container.rb b/lib/dry/container.rb index 02e6d02..1236948 100644 --- a/lib/dry/container.rb +++ b/lib/dry/container.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require "dry-configurable" require "dry/container/error" require "dry/container/namespace" require "dry/container/registry" diff --git a/lib/dry/container/mixin.rb b/lib/dry/container/mixin.rb index 8f9c260..2192e06 100644 --- a/lib/dry/container/mixin.rb +++ b/lib/dry/container/mixin.rb @@ -4,6 +4,46 @@ module Dry class Container + # @api public + class Config + DEFAULT_NAMESPACE_SEPARATOR = "." + DEFAULT_RESOLVER = Resolver.new + DEFAULT_REGISTRY = Registry.new + + # @api public + attr_accessor :namespace_separator + + # @api public + attr_accessor :resolver + + # @api public + attr_accessor :registry + + # @api private + def initialize( + namespace_separator: DEFAULT_NAMESPACE_SEPARATOR, + resolver: DEFAULT_RESOLVER, + registry: DEFAULT_REGISTRY + ) + @namespace_separator = namespace_separator + @resolver = resolver + @registry = registry + end + end + + # @api public + module Configuration + # @api public + def config + @config ||= Config.new + end + + # @api public + def configure + yield config + end + end + PREFIX_NAMESPACE = lambda do |namespace, key, config| [namespace, key].join(config.namespace_separator) end @@ -45,13 +85,9 @@ def inherited(subclass) end base.class_eval do - extend ::Dry::Configurable + extend Configuration extend hooks_mod - setting :registry, default: Dry::Container::Registry.new - setting :resolver, default: Dry::Container::Resolver.new - setting :namespace_separator, default: "." - @_container = ::Concurrent::Hash.new end end @@ -67,13 +103,9 @@ def initialize(*args, &block) # @private def self.included(base) base.class_eval do - extend ::Dry::Configurable + extend Configuration prepend Initializer - setting :registry, default: Dry::Container::Registry.new - setting :resolver, default: Dry::Container::Resolver.new - setting :namespace_separator, default: "." - def config self.class.config end