Class: Synapse::Configuration::ContainerBuilder

Inherits:
Object
  • Object
show all
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

See Also:

  • Synapse#build

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container) ⇒ undefined

Parameters:



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

#containerContainer (readonly)

Returns:



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

Parameters:

  • initializer (Proc)

Returns:

  • (undefined)


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

Parameters:

  • identifier (Symbol) (defaults to: nil)
  • block (Proc)

Returns:

  • (undefined)

See Also:



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

Parameters:

  • block (Proc)

Returns:

  • (undefined)


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

Parameters:

  • identifier (Symbol) (defaults to: nil)
  • block (Proc)

Returns:

  • (undefined)

See Also:



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

Examples:

definition :account_projection do
  tag :event_listener, :projection
  use_factory do
    AccountProjection.new
  end
end

Parameters:

  • id (Symbol) (defaults to: nil)
  • block (Proc)

Returns:

  • (undefined)

See Also:



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

Parameters:

  • identifier (Symbol) (defaults to: nil)
  • block (Proc)

Returns:

  • (undefined)

See Also:



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.

Examples:

factory :account_projection, :tag => [:event_listener, :projection] do
  AccountProjection.new
end

Parameters:

  • id (Symbol)
  • args (Object...)
  • block (Proc)

Returns:

  • (undefined)

See Also:



82
83
84
85
86
87
88
89
90
91
# File 'lib/synapse/configuration/container_builder.rb', line 82

def factory(id, *args, &block)
  options = args.extract_options!

  with_definition_builder DefinitionBuilder, id do
    use_factory(&block)
    if options.has_key? :tag
      tag(*options.fetch(:tag))
    end
  end
end

#gateway(identifier = nil, &block) ⇒ undefined

Creates and configures a command gateway

Parameters:

  • identifier (Symbol) (defaults to: nil)
  • block (Proc)

Returns:

  • (undefined)

See Also:

  • CommandGatewayBusDefinitionBuilder


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

#initializersArray

Registered initializers that will be executed upon instantiation

Returns:

  • (Array)


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.

Parameters:

  • identifier (Symbol) (defaults to: nil)
  • block (Proc)

Returns:

  • (undefined)

See Also:



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

Parameters:

  • identifier (Symbol) (defaults to: nil)
  • block (Proc)

Returns:

  • (undefined)

See Also:



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

Parameters:

  • identifier (Symbol) (defaults to: nil)
  • block (Proc)

Returns:

  • (undefined)

See Also:



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

Parameters:

  • identifier (Symbol) (defaults to: nil)
  • block (Proc)

Returns:

  • (undefined)

See Also:



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

Parameters:

  • identifier (Symbol) (defaults to: nil)
  • block (Proc)

Returns:

  • (undefined)

See Also:



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

Parameters:

  • identifier (Symbol) (defaults to: nil)
  • block (Proc)

Returns:

  • (undefined)

See Also:



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