.resolve
accepts an optional fallback block, similar to howHash#fetch
works (flash-gordon)container.resolve('missing_key') { :fallback } # => :fallback
.decorate
can (again) work with static values. Also, it can take a block instead ofwith
(flash-gordon)container.register('key', 'value') container.decorate('key') { |v| "<'#{v}'>" } container.resolve('key') # => "<'value'>"
- Added
Mixin#dup
andMixin#clone
, now copies don't share underlying containers (flash-gordon)
- [BREAKING] Now only Ruby 2.3 and above is supported (flash-gordon)
-
Symbols are now coerced to strings when resolving stubbed dependencies (cthulhu666)
-
Stubbing keys not present in container will raise an error (flash-gordon)
This means after upgrading you may see errors like this
ArgumentError (cannot stub "something" - no such key in container)
Be sure you register dependencies before using them. The new behavior will likely save quite a bit of time when debugging ill-configured container setups.
-
Namespace DSL resolves keys relative to the current namespace, see the corresponding changes (yuszuv)
-
Registered objects can be decorated with the following API (igor-alexandrov)
class CreateUser def call(params) # ... end end container.register('create_user') { CreateUser.new } container.decorate('create_user', with: ShinyLogger.new) # Now subsequent resolutions will return a wrapped object container.resolve('create_user') # => #<ShinyLogger @obj=#<CreateUser:0x...>]>
-
Freezing a container now prevents further registrations (flash-gordon)
- Handling container items was generalized in #34 (GabrielMalakias)
Dry::Container::Mixin#each
- provides a means of seeing what all is registered in the container (jeremyf)
- Including mixin into a class with a custom initializer (maltoe)
memoize
option to#register
- memoizes items on first resolve (ivoanjo)
required_ruby_version
set to>= 2.0.0
(artofhuman)