Sha256: ce98648d088d4cf1f6eb7e60a9c7dfeb7e5ccd6ba0ec25f06f10dd0f7ff1780b

Contents?: true

Size: 903 Bytes

Versions: 2

Compression:

Stored size: 903 Bytes

Contents

Using the libraries is as simple as requiring the file that has the service definitions, and then invoking the @#register_services@ module function:

{{{lang=ruby,number=true,caption=Example of using a Needle-enabled library
require 'needle'

reg = Needle::Registry.new
reg.define do |b|
  b.foo { Foo.new }

  require 'crypto/services'
  Crypto.register_services( reg )
end

prng = reg.crypto.prng
}}}

To make this easier, the Container class has a convenience method named @#require@:

{{{lang=ruby,number=true,caption=Example of using Container#require
require 'needle'

reg = Needle::Registry.new
reg.define do |b|
  b.foo { Foo.new }
  b.require 'crypto/services', "Crypto"
end

prng = reg.crypto.prng
}}}

The @Container#require@ method will require the file, and then look for a @#register_services@ method of the named module. It will execute that method, passing the container as an argument.

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
needle-1.2.1 doc/manual/parts/libraries_using.txt
needle-1.3.0 doc/manual/parts/libraries_using.txt