-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
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)
endNine 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) }