Sha256: a5cef80e5886dc414a8b8b6c130cf4f33d73fbaaa10a9f422d81d21c287a27b4
Contents?: true
Size: 1.48 KB
Versions: 2
Compression:
Stored size: 1.48 KB
Contents
Creating a registry is as simple as calling @Needle::Registry.new@. This will give you a new registry object, bootstrapped to contain a few general services. {{{lang=ruby,number=true,caption=Creating a registry require 'needle' registry = Needle::Registry.new }}} Once you have the reference to the registry, you can register services with it, create new namespaces in it, and so forth. Alternatively, you can pass a block to @#new@: {{{lang=ruby,number=true,caption=Creating a registry with a block registry = Needle::Registry.new do |r| ... end }}} The parameter to the block will be a reference to the registry. This allows you to register services with the registry as soon as it is created. Another convenience method is @#define!@: {{{lang=ruby,number=true,caption=Creating a registry with #define! registry = Needle::Registry.define! do ... end }}} This block accepts no parameters, and evaluates the block as if it were passed to @Registry#define!@ (see below). There can be problems with using @define!@, however, since it uses @instance_eval@ to evaluate the block within the context of another object. If you find yourself running into scoping issues, you might want to consider using @#define@: {{{lang=ruby,number=true,caption=Creating a registry with #define registry = Needle::Registry.define do |b| ... end }}} This block accepts a single parameter--a "builder" object to aid in registering services--and evaluates the block as if it were passed to @Registry#define@ (see below).
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
needle-1.2.1 | doc/manual/parts/02_creating.txt |
needle-1.3.0 | doc/manual/parts/02_creating.txt |