The Complex instantiator is a more sophisticated way of instantiating services. It provides for the wiring of dependencies into the new service "automatically" (based on specified dependencies). This instantiator is what allows Copland to claim support for "dependency injection."
|[R]||construction_parms||The hash of parameters to pass to the instantiating factory.|
|[R]||factory_point||The service point of the factory to use to instantiate the service.|
Create a new Complex instantiator for the given service point, using the given definition hash.
# File lib/copland/instantiator/complex.rb, line 56 56: def initialize( point, definition ) 57: super point, definition 58: 59: @factory_id = definition[ "factory" ] || "copland.BuilderFactory" 60: @factory_id = @factory_id.value if @factory_id.respond_to?( :value ) 61: 62: @construction_parms = definition.dup 63: @construction_parms.delete "factory" 64: end
Create a new instance of the service via the factory service. The constructor parameters are passed through the factory’s schema (if any) before passing them to the factory’s create_instance method.
# File lib/copland/instantiator/complex.rb, line 81 81: def instantiate 82: @factory = @factory_point.instance unless @factory 83: 84: parms = @construction_parms 85: schema = @factory_point.schema 86: if schema.respond_to?( :process ) 87: parms = schema.process( @factory_point, point, parms ) 88: end 89: 90: @factory.create_instance( point, parms ) 91: end
Validates the parameters to this instantiator by running them through the schema of the associated factory service point (if any).
# File lib/copland/instantiator/complex.rb, line 68 68: def validate! 69: @factory_point = point.find_service_point( @factory_id ) 70: 71: schema = @factory_point.schema 72: if schema.respond_to?( :validate ) 73: schema.validate @factory_point, point, construction_parms 74: end 75: end