Hey 
the great dependency injection feature is not available in Repos out of the box. Following does not work:
module Documents
module Repos
class DocumentRepo < Documents::DB::Repo
include Deps["utils.now"]
def create(hash)
puts now.inspect # now: nil
end
end
end
end
@timriley Should we fix this? The only workaround, if found, is to use the dependencies via the container:
def create(hash)
Documents::Slice["utils.now"]
end
Repos should absolutely be able to work with DI, so I definitely consider this a bug! Probably an issue with the constructor methods we’ve implemented on Hanami::DB::Repo.
Ah, here’s an issue I already created: Deps included within repos are not made available · Issue #1483 · hanami/hanami · GitHub
This has a hint about how to fix it. It should be a simple one.
Oh, great.
I can confirm. Changing define_new
to
def define_new
resolve_rom = method(:resolve_rom)
define_method(:new) do |**kwargs|
super(container: kwargs.fetch(:container) { resolve_rom.() }, **kwargs.except(:container))
end
end
solves the issue.
@timriley Do you want me to prepare a PR? Or do you have any further thoughts here?
If you could prepare a PR, that would be amazing, thank you!
Having a simple test to verify this behavior would be good too.