Hi,
I am testing dry auto inject right now.
I did something like this:
Dependency = Dry::AutoInject(Class.new do
extend Dry::Container::Mixin
register InterfaceA do
InterfaceAImpl.new
end
end)
And a class B can use the dependency like this:
include Dependency[InterfaceA]
It works fine, but it seems like a coincidence.
If we take a look into lib/dry/auto_inject/dependency_map.rb
VALID_NAME = /([a-z_][a-zA-Z_0-9]*)$/
is defined, which causes the depencency map to be
created with the key ânterfaceAâ (starting upper cased letter is removed) and in case I have a namespaced class the namespace is removed.
So my question is what do you think about usage of constants/classes?
What I like about that is, that it seems kind of like an interface.
I declare dependency on an interface and I do not care about the registered implementation class.
I can look up the interface class and see which methods will be available.
In case of support, I would like to adjust the name_for method in dependency_map.rb
to handle classes and especially namespaces well.
Best regards