Uninitialized constant <AppName>::Import

I’m using dry-rails v. 0.3 and have the following issue: MyAppName::Import constant is uninitialized. I’m not sure if I should do some initialization, the documentation states:

The auto-injection mechanism is also set up for you automatically.
https://dry-rb.org/gems/dry-rails/0.1/#using-code-import-code-mixin

I have the following configuration:

# config/initializers/system.rb
# frozen_string_literal: true
Dry::Rails.container do
  auto_register!('app/operations')
  register(:logger, Logger.new($stdout))
end

Both files from operations and logger are visible when using MyAppName::Container, for example:

ShoperIntegrator::Container['products.generate_shoper_description']

In the app/operations/debug I have the following 2 files:

# app/operations/debug/printer.rb
module Debug
  class Printer
    def print(message)
      puts "Debug::Printer: #{message}"
    end
  end
end

# app/operations/debug/try_inject.rb
module Debug
  class TryInject
    # This one does not work
    # include ShoperIntegrator::Import['debug.printer']

    def perform
      # This one works
      printer = ShoperIntegrator::Container['debug.printer']
      printer.print('Hey!')
    end
  end
end

And again, here Container woks perfectly and Import not at all.
Did I missed some configuration step?

Hello @tomaszwojcik!

That constant is now named Deps and can be configured to anything you want by setting config.auto_inject_constant. This change was introduced on 0.2.0.

I think we have an open pull request which updates docs to include this information.

1 Like

Works like a charm! Thanks :smile:

Yeah, updated docs would be super nice, the gem is 0.3 now, and docs are for 0.1.

1 Like

Hey hey, I just published updated docs for 0.2 and 0.3, so the latest are here https://dry-rb.org/gems/dry-rails/0.3/

1 Like