Dry-auto-inject. Inject dependencies with Procs

Hey, injecting dependencies with Procs can be super handy.

Pros:

  1. Code editor navigation to a dependency class will work
  2. Application code will be simplified, as you don’t need to put every service class to the “container”
  3. You don’t need to teach all newbies what is a “DI Container” and how dependencies are resolved
  4. Just because DI is a simple pattern that must work as is, without any dependencies to other patterns

Example:

class MyClass
  include DI[
     mailer: proc { SomeMailer.new }, # uses Proc
     logger: proc { MyLogger },       # uses Proc
     ab_tests:  'app.ab_tests',       # uses container resolver
  ]
end

It should be relatively simple to implement, just changing

container[identifier]
# to
identifier.is_a?(Proc) identifier.call : container[identifier]

I would like to add some Pull Request if this idea will be accepted