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
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
-
.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.
-
#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
Registered initializers that will be executed upon instantiation.
-
#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.
-
#unit_factory(identifier = nil, &block) ⇒ undefined
Creates and configures a unit of work factory.
-
#upcaster_chain(identifier = nil, &block) ⇒ undefined
Creates and configures an upcaster chain.
Constructor Details
#initialize(container) ⇒ undefined
27 28 29 30 31 32 33 34 35 |
# File 'lib/synapse/configuration/container_builder.rb', line 27 def initialize(container) @container = container if initializers initializers.each do |initializer| build_with(&initializer) end end end |
Instance Attribute Details
#container ⇒ Container (readonly)
23 24 25 |
# File 'lib/synapse/configuration/container_builder.rb', line 23 def container @container end |
Class Method Details
.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
10 11 12 |
# File 'lib/synapse/configuration/component/command_bus.rb', line 10 def async_command_bus(identifier = nil, &block) with_definition_builder AsynchronousCommandBusDefinitionBuilder, identifier, &block end |
#build_with(&block) ⇒ undefined
Executes the given block in the context of the container builder
41 42 43 |
# File 'lib/synapse/configuration/container_builder.rb', line 41 def build_with(&block) instance_exec(&block) end |
#converter_factory(identifier = nil, &block) ⇒ undefined
Creates and configures a converter factory for serialization
10 11 12 |
# File 'lib/synapse/configuration/component/serialization.rb', line 10 def converter_factory(identifier = nil, &block) with_definition_builder ConverterFactoryDefinitionBuilder, identifier, &block end |
#definition(id = nil, &block) ⇒ undefined
Executes the given block in the context of a new definition builder
60 61 62 |
# File 'lib/synapse/configuration/container_builder.rb', line 60 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
10 11 12 |
# File 'lib/synapse/configuration/component/event_sourcing.rb', line 10 def es_repository(identifier = nil, &block) with_definition_builder EventSourcingRepositoryDefinitionBuilder, identifier, &block end |
#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.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/synapse/configuration/container_builder.rb', line 82 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
30 31 32 |
# File 'lib/synapse/configuration/component/command_bus.rb', line 30 def gateway(identifier = nil, &block) with_definition_builder CommandGatewayBusDefinitionBuilder, identifier, &block end |
#initializers ⇒ Array
Registered initializers that will be executed upon instantiation
8 |
# File 'lib/synapse/configuration/container_builder.rb', line 8 class_attribute :initializers |
#serializer(identifier = nil, &block) ⇒ undefined
Creates and configures a serializer for partitioning, event storage, etc.
20 21 22 |
# File 'lib/synapse/configuration/component/serialization.rb', line 20 def serializer(identifier = nil, &block) with_definition_builder SerializerDefinitionBuilder, identifier, &block end |
#simple_command_bus(identifier = nil, &block) ⇒ undefined
Creates and configures a simple command bus
20 21 22 |
# File 'lib/synapse/configuration/component/command_bus.rb', line 20 def simple_command_bus(identifier = nil, &block) with_definition_builder SimpleCommandBusDefinitionBuilder, identifier, &block end |
#simple_event_bus(identifier = nil, &block) ⇒ undefined
Creates and configures a simple event bus
10 11 12 |
# File 'lib/synapse/configuration/component/event_bus.rb', line 10 def simple_event_bus(identifier = nil, &block) with_definition_builder SimpleEventBusDefinitionBuilder, identifier, &block end |
#simple_repository(identifier = nil, &block) ⇒ undefined
Creates and configures a simple repository
10 11 12 |
# File 'lib/synapse/configuration/component/repository.rb', line 10 def simple_repository(identifier = nil, &block) with_definition_builder SimpleRepositoryDefinitionBuilder, identifier, &block end |
#unit_factory(identifier = nil, &block) ⇒ undefined
Creates and configures a unit of work factory
17 18 19 |
# File 'lib/synapse/configuration/component/uow.rb', line 17 def unit_factory(identifier = nil, &block) with_definition_builder UnitOfWorkFactoryDefinitionBuilder, identifier, &block end |
#upcaster_chain(identifier = nil, &block) ⇒ undefined
Creates and configures an upcaster chain
10 11 12 |
# File 'lib/synapse/configuration/component/upcasting.rb', line 10 def upcaster_chain(identifier = nil, &block) with_definition_builder UpcasterChainDefinitionBuilder, identifier, &block end |