Sha256: 07540aaec4763939dd0d802d09c490c9b8e6630817a97aa1662e2cb1f9e4ca22
Contents?: true
Size: 1.18 KB
Versions: 2
Compression:
Stored size: 1.18 KB
Contents
A _definition context_ is used when registering services using any of the @#define@ interfaces. For example, @Container#define@ yields an instance of a definition context to the given block, and @Container#define!@ uses the block in an @instance_eval@ on a definition context. The default implementation used for definition contexts is defined by the @:definition_context_factory@ service. By default, this service returns @Needle::DefinitionContext@, but you can specify your own definition context implementations by overriding this service. In fact, each namespace could have its own definition context implementation, if needed. Consider the following contrived example, where you want to provide a convenient way to register services of type Hash. {{{lang=ruby,number=true,caption=Custom DefinitionContext example class MyDefinitionContext < Needle::DefinitionContext def register_hash( name, opts={} ) this_container.register( name, opts ) { Hash.new } end end reg = Needle::Registry.new reg.register( :definition_context_factory ) { MyDefinitionContext } reg.define do |b| b.register_hash( :test1 ) b.register_hash( :test2 ) end reg.test1[:key] = "value" reg.test2[:foo] = "bar" }}}
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
needle-1.2.1 | doc/manual/parts/customizing_contexts.txt |
needle-1.3.0 | doc/manual/parts/customizing_contexts.txt |