Sha256: 7c4a86573f118f08c00794ccaed44bfa6d296f631883a8a3fb94fbd24a32c6c6

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

This centralization is implemented by creating a module for each library you want to have services for. That module should then define a module function called (by default) @register_services@. This function should accept a single parameter--the Needle container that the services will be added to.

For example, if I had a library of cryptographic routines and I wanted to make them accessible as Needle services, I would create a module to contain the service definitions. Typically, this module will be defined in a file called "services.rb", although you can certainly name it whatever you like.

{{{lang=ruby,number=true,caption=Needle-enabled library example
module Crypto
  
  def register_services( container )
    container.namespace_define( :crypto ) do |b|
      b.prng do
        require 'crypto/prng'
        PRNG.new
      end

      b.des do
        require 'crypto/des'
        DES.new
      end

      ...
    end
  end
  module_function :register_services

end
}}}

Notice that there are no explicit dependencies on Needle, only on the interfaces Needle publishes. Thus, third-parties can add service configuration modules to their libraries without introducing dependencies on Needle.

Once a service library has been created, it can then be accessed from another library or application that wishes to import those services.

Version data entries

2 entries across 2 versions & 1 rubygems

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