dry-rb / dry-container

A simple, configurable object container implemented in Ruby
https://dry-rb.org/gems/dry-container
MIT License
335 stars 41 forks source link

Replace dep on dry-configurable with a simple Configuration mod #84

Closed solnic closed 2 years ago

solnic commented 2 years ago

This removes dependency on dry-configurable as dry-container is a lower-level gem and it shouldn't depend on dry-configurable, which is a higher-level gem. Originally, this wasn't the case, but dry-configurable has grown into a quite advanced configuration system (and will most likely continue to evolve).

Configuration needs of dry-container are very basic, they don't justify the usage of dry-configurable. Notice that dry-container is one of the oldest dry-rb gems and throughout the years its config (3 config values: namespace separator, registry and resolver) have been always the same.

Stuff works the same now:

irb(main):001:1* class MyContainer
irb(main):002:1*   include Dry::Container::Mixin
irb(main):003:0> end
=> MyContainer
irb(main):004:0> MyContainer.config.namespace_separator = "/"
=> "/"
irb(main):005:0> mc = MyContainer.new
=> #<MyContainer:0x00007f9a68962a30 @_container={}>
irb(main):006:0> mc.namespace("foo") { |foo| foo.register("bar", :bar) }
=> #<MyContainer:0x00007f9a68962a30 @_container={"foo/bar"=>#<Dry::Container::Item::Callable:0x00007f9a689df990 @item=:bar, @options={:call=>false}>}>
irb(main):007:0> mc["foo/bar"]
=> :bar
solnic commented 2 years ago

Currently, dry-configurable's features propagate to dry-system, and someone may use them. Maybe dry-system's container should continue to have them. Other than this, 👍

Yeah so dry-system's extends its container with Dry::Configurable and the gem depends on dry-configurable explicitly. So this is not a problem (luckily 😅).

solnic commented 2 years ago

@timriley are you OK with this?

timriley commented 2 years ago

@solnic Don't forget to remove dry-configurable from project.yml! Otherwise the change in the gemspec will get overridden.

timriley commented 2 years ago

Thanks for making this change, @solnic, glad to see it go in!