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,
lib/synapse/configuration/component/process_manager.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:



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

#containerContainer (readonly)

Returns:



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

Examples:

class ContainerBuilder
  builder :simple_event_bus, SimpleEventBusDefinitionBuilder
end

Parameters:

  • name (Symbol)
  • builder_class (Class)

Returns:

  • (undefined)


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

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)

    Identifier of the definition

  • block (Proc)

    Executed in the context of the definition builder

Returns:

  • (undefined)

See Also:



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

Parameters:

  • block (Proc)

Returns:

  • (undefined)


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

Parameters:

  • identifier (Symbol) (defaults to: nil)

    Identifier of the definition

  • block (Proc)

    Executed in the context of the definition builder

Returns:

  • (undefined)

See Also:



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

Parameters:

  • identifier (Symbol) (defaults to: nil)

    Identifier of the definition

  • block (Proc)

    Executed in the context of the definition builder

Returns:

  • (undefined)

See Also:



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

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:



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

Parameters:

  • identifier (Symbol) (defaults to: nil)

    Identifier of the definition

  • block (Proc)

    Executed in the context of the definition builder

Returns:

  • (undefined)

See Also:



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.

Examples:

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

Parameters:

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

Returns:

  • (undefined)

See Also:



108
109
110
111
112
113
114
115
116
117
# File 'lib/synapse/configuration/container_builder.rb', line 108

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)

    Identifier of the definition

  • block (Proc)

    Executed in the context of the definition builder

Returns:

  • (undefined)

See Also:



15
# File 'lib/synapse/configuration/component/command_bus.rb', line 15

builder :gateway, CommandGatewayDefinitionBuilder

#initializersArray

Registered initializers that will be executed upon instantiation

Returns:

  • (Array)


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

Parameters:

  • identifier (Symbol) (defaults to: nil)

    Identifier of the definition

  • block (Proc)

    Executed in the context of the definition builder

Returns:

  • (undefined)

See Also:



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

Parameters:

  • identifier (Symbol) (defaults to: nil)

    Identifier of the definition

  • block (Proc)

    Executed in the context of the definition builder

Returns:

  • (undefined)

See Also:



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

Parameters:

  • identifier (Symbol) (defaults to: nil)

    Identifier of the definition

  • block (Proc)

    Executed in the context of the definition builder

Returns:

  • (undefined)

See Also:



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.

Parameters:

  • identifier (Symbol) (defaults to: nil)

    Identifier of the definition

  • block (Proc)

    Executed in the context of the definition builder

Returns:

  • (undefined)

See Also:



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

Parameters:

  • identifier (Symbol) (defaults to: nil)

    Identifier of the definition

  • block (Proc)

    Executed in the context of the definition builder

Returns:

  • (undefined)

See Also:



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

Parameters:

  • identifier (Symbol) (defaults to: nil)

    Identifier of the definition

  • block (Proc)

    Executed in the context of the definition builder

Returns:

  • (undefined)

See Also:



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

Parameters:

  • identifier (Symbol) (defaults to: nil)

    Identifier of the definition

  • block (Proc)

    Executed in the context of the definition builder

Returns:

  • (undefined)

See Also:



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

Parameters:

  • identifier (Symbol) (defaults to: nil)

    Identifier of the definition

  • block (Proc)

    Executed in the context of the definition builder

Returns:

  • (undefined)

See Also:



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

Parameters:

  • identifier (Symbol) (defaults to: nil)

    Identifier of the definition

  • block (Proc)

    Executed in the context of the definition builder

Returns:

  • (undefined)

See Also:



7
# File 'lib/synapse/configuration/component/upcasting.rb', line 7

builder :upcaster_chain, UpcasterChainDefinitionBuilder