These are chat archives for dry-rb/chat

21st
Jul 2015
Andy Holland
@AMHOL
Jul 21 2015 21:59
@solnic not sure how far you got or what code you ended up with for the container stuff, but thinking sth like this would be better:
class Container
  extend Dry::Container::Mixin

  register('rom') do
    ROM.env
  end

  register('repositories.user') do
    resolve('rom').relation(:users)
  end
end

module ContainerResolution
  def self.extended(klass)
    klass.delegate :resolve, to: Container
  end

  def use(key, **options)
    method = options.fetch(:as, key)

    define_method(method) do
      resolve(key)
    end

    memoize(*keys) if options.fetch(:memoize, false)
  end
end

class UsersController
  extend ContainerResolution

  use 'repositories.user', as: :user_repository

  def index
    user_repository.all.to_a
  end
end
Just with the use 'sth', as: :sth_els, I like the namespaces with the string keys