Class: Synapse::Configuration::ContainerBuilder
- Inherits:
-
Object
- Object
- Synapse::Configuration::ContainerBuilder
- Defined in:
- lib/synapse/configuration/container_builder.rb,
lib/synapse/configuration/component/uow.rb,
lib/synapse/configuration/component/event_bus.rb,
lib/synapse/configuration/component/upcasting.rb,
lib/synapse/configuration/component/repository.rb,
lib/synapse/configuration/component/command_bus.rb,
lib/synapse/configuration/component/serialization.rb,
lib/synapse/configuration/component/event_sourcing.rb,
lib/synapse/configuration/component/process_manager.rb
Overview
Provides a DSL for end-users to easily configure the Synapse service container
Instance Attribute Summary collapse
- #container ⇒ Container readonly
Class Method Summary collapse
-
.builder(name, builder_class) ⇒ undefined
Registers a definition builder that can be used as a shortcut for configuration.
-
.initializer(&initializer) ⇒ undefined
Registers a block that will be executed upon instantiation of a container builder.
Instance Method Summary collapse
-
#async_command_bus(identifier = nil, &block) ⇒ undefined
Creates and configures an asynchronous command bus.
-
#build_with(&block) ⇒ undefined
Executes the given block in the context of the container builder.
-
#container_resource_injector(identifier = nil, &block) ⇒ undefined
Creates and configures a resource injector that uses the service container.
-
#converter_factory(identifier = nil, &block) ⇒ undefined
Creates and configures a converter factory for serialization.
-
#definition(id = nil, &block) ⇒ undefined
Executes the given block in the context of a new definition builder.
-
#es_repository(identifier = nil, &block) ⇒ undefined
Creates and configures an event sourcing repository.
-
#factory(id, *args, &block) ⇒ undefined
Simple usage of the definition builder.
-
#gateway(identifier = nil, &block) ⇒ undefined
Creates and configures a command gateway.
- #initialize(container) ⇒ undefined constructor
-
#initializers ⇒ Array<Proc>
Registered initializers that will be executed upon instantiation.
-
#interval_snapshot_policy(identifier = nil, &block) ⇒ undefined
Creates and configures an interval-based snapshot policy.
-
#process_factory(identifier = nil, &block) ⇒ undefined
Creates and configures a generic process factory.
-
#process_manager(identifier = nil, &block) ⇒ undefined
Creates and configures a mapping process manager.
-
#serializer(identifier = nil, &block) ⇒ undefined
Creates and configures a serializer for partitioning, event storage, etc.
-
#simple_command_bus(identifier = nil, &block) ⇒ undefined
Creates and configures a simple command bus.
-
#simple_event_bus(identifier = nil, &block) ⇒ undefined
Creates and configures a simple event bus.
-
#simple_repository(identifier = nil, &block) ⇒ undefined
Creates and configures a simple repository.
-
#snapshot_taker(identifier = nil, &block) ⇒ undefined
Creates and configures an aggregate snapshot taker.
-
#upcaster_chain(identifier = nil, &block) ⇒ undefined
Creates and configures an upcaster chain.
Constructor Details
#initialize(container) ⇒ undefined
50 51 52 53 54 55 56 57 58 |
# File 'lib/synapse/configuration/container_builder.rb', line 50 def initialize(container) @container = container if initializers initializers.each do |initializer| build_with(&initializer) end end end |
Instance Attribute Details
#container ⇒ Container (readonly)
46 47 48 |
# File 'lib/synapse/configuration/container_builder.rb', line 46 def container @container end |
Class Method Details
.builder(name, builder_class) ⇒ undefined
Registers a definition builder that can be used as a shortcut for configuration
39 40 41 42 43 |
# File 'lib/synapse/configuration/container_builder.rb', line 39 def self.builder(name, builder_class) define_method name do |identifier = nil, &block| with_definition_builder builder_class, identifier, &block end end |
.initializer(&initializer) ⇒ undefined
Registers a block that will be executed upon instantiation of a container builder
This is useful for defining common services that are likely to be depended upon by other services being built
17 18 19 20 |
# File 'lib/synapse/configuration/container_builder.rb', line 17 def self.initializer(&initializer) self.initializers ||= Array.new self.initializers.push initializer end |
Instance Method Details
#async_command_bus(identifier = nil, &block) ⇒ undefined
Creates and configures an asynchronous command bus
9 |
# File 'lib/synapse/configuration/component/command_bus.rb', line 9 builder :async_command_bus, AsynchronousCommandBusDefinitionBuilder |
#build_with(&block) ⇒ undefined
Executes the given block in the context of the container builder
65 66 67 |
# File 'lib/synapse/configuration/container_builder.rb', line 65 def build_with(&block) instance_exec(&block) end |
#container_resource_injector(identifier = nil, &block) ⇒ undefined
Creates and configures a resource injector that uses the service container
9 |
# File 'lib/synapse/configuration/component/process_manager.rb', line 9 builder :container_resource_injector, ContainerResourceInjectorDefinitionBuilder |
#converter_factory(identifier = nil, &block) ⇒ undefined
Creates and configures a converter factory for serialization
8 |
# File 'lib/synapse/configuration/component/serialization.rb', line 8 builder :converter_factory, ConverterFactoryDefinitionBuilder |
#definition(id = nil, &block) ⇒ undefined
Executes the given block in the context of a new definition builder
85 86 87 |
# File 'lib/synapse/configuration/container_builder.rb', line 85 def definition(id = nil, &block) with_definition_builder DefinitionBuilder, id, &block end |
#es_repository(identifier = nil, &block) ⇒ undefined
Creates and configures an event sourcing repository
9 |
# File 'lib/synapse/configuration/component/event_sourcing.rb', line 9 builder :es_repository, EventSourcingRepositoryDefinitionBuilder |
#factory(id, *args, &block) ⇒ undefined
Simple usage of the definition builder
The given block is used as a deferred factory and will be executed in the context of the definition builder. If a tag option is provided, the definition will be tagged with the given symbols.
The definition that is created will be a singleton.
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/synapse/configuration/container_builder.rb', line 108 def factory(id, *args, &block) = args. with_definition_builder DefinitionBuilder, id do use_factory(&block) if .has_key? :tag tag(*.fetch(:tag)) end end end |
#gateway(identifier = nil, &block) ⇒ undefined
Creates and configures a command gateway
15 |
# File 'lib/synapse/configuration/component/command_bus.rb', line 15 builder :gateway, CommandGatewayDefinitionBuilder |
#initializers ⇒ Array<Proc>
Registered initializers that will be executed upon instantiation
8 |
# File 'lib/synapse/configuration/container_builder.rb', line 8 class_attribute :initializers |
#interval_snapshot_policy(identifier = nil, &block) ⇒ undefined
Creates and configures an interval-based snapshot policy
15 |
# File 'lib/synapse/configuration/component/event_sourcing.rb', line 15 builder :interval_snapshot_policy, IntervalSnapshotPolicyDefinitionBuilder |
#process_factory(identifier = nil, &block) ⇒ undefined
Creates and configures a generic process factory
12 |
# File 'lib/synapse/configuration/component/process_manager.rb', line 12 builder :process_factory, GenericProcessFactoryDefinitionBuilder |
#process_manager(identifier = nil, &block) ⇒ undefined
Creates and configures a mapping process manager
15 |
# File 'lib/synapse/configuration/component/process_manager.rb', line 15 builder :process_manager, MappingProcessManagerDefinitionBuilder |
#serializer(identifier = nil, &block) ⇒ undefined
Creates and configures a serializer for partitioning, event storage, etc.
11 |
# File 'lib/synapse/configuration/component/serialization.rb', line 11 builder :serializer, SerializerDefinitionBuilder |
#simple_command_bus(identifier = nil, &block) ⇒ undefined
Creates and configures a simple command bus
12 |
# File 'lib/synapse/configuration/component/command_bus.rb', line 12 builder :simple_command_bus, SimpleCommandBusDefinitionBuilder |
#simple_event_bus(identifier = nil, &block) ⇒ undefined
Creates and configures a simple event bus
7 |
# File 'lib/synapse/configuration/component/event_bus.rb', line 7 builder :simple_event_bus, SimpleEventBusDefinitionBuilder |
#simple_repository(identifier = nil, &block) ⇒ undefined
Creates and configures a simple repository
8 |
# File 'lib/synapse/configuration/component/repository.rb', line 8 builder :simple_repository, SimpleRepositoryDefinitionBuilder |
#snapshot_taker(identifier = nil, &block) ⇒ undefined
Creates and configures an aggregate snapshot taker
12 |
# File 'lib/synapse/configuration/component/event_sourcing.rb', line 12 builder :snapshot_taker, AggregateSnapshotTakerDefinitionBuilder |
#upcaster_chain(identifier = nil, &block) ⇒ undefined
Creates and configures an upcaster chain
7 |
# File 'lib/synapse/configuration/component/upcasting.rb', line 7 builder :upcaster_chain, UpcasterChainDefinitionBuilder |