Explanation of super in intitialize

#1

I started using dry-auto_inject gem with kwargs strategy, but I am not sure if I understand why super(**dependencies) should be in initialize method when including Dry Container in my class.

https://dry-rb.org/gems/dry-auto_inject/how-does-it-work/

In example below, class MyService is child of base_service class.

#base_service.rb
class BaseService
  def self.call(*args)
    new(*args).call
  end

  def call
    raise 'Not implemented'
  end
end

#my_service.rb
class MyService < BaseService
include InjectServices[ 'some_service', 'external_service' ]

  def initialize(fields:, **dependencies)
    @fields = fields
    super(**dependencies)
  end
end

Do I need super(**dependencies)? I would be grateful if I could get a more detailed explanation.

#2

Yes, if you’re writing your own #initialize, you need to pass the **dependencies up to the #initialize provided by the injector mixin, otherwise it won’t properly receive and assign the auto-injected dependencies that are being passed in from the .new method that the injector also provides.