Skip to content

Use of initializer blocks could be more streamlined #19

@KevinBrowne

Description

@KevinBrowne

When registering a dependency with an initializer block, Sinject::Container#register requires the class to be provided as a parameter and, essentially, to be provided in the block. This introduces a bit of tedious boilerplate, like this:

require 'sinject'
container = Sinject::Container.new(false)

module Some
  module Deeply
    module Nested
      module NameSpace
        class Thing
          def initialize(whatever)
          # etc.
        end
      end
    end
  end
end

container.register(key: :foo,
                   class: Some::Deeply::Nested::NameSpace::Thing) do
  Some::Deeply::Nested::NameSpace::Thing.new(something)
end

Nine times out of ten, the type you want to instantiate in the block is the exact same type you specified as the class argument. It would be a nice convenience if that class could be passed to the block:

container.register(key: :foo,
                   class: Some::Deeply::Nested::NameSpace::Thing) { |klass| klass.new(something) }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions