Skip to content

Commit

Permalink
Add functional options to route functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Sep 26, 2023
1 parent f7de643 commit 88cba77
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 21 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ The format is based on [Keep a Changelog], and this project adheres to

### Added

- **[ENGINE BC]** Added functional options to the following methods and functions:
- **[ENGINE BC]** Added placeholder option parameters to the following methods and functions:
- `ApplicationConfigurer.RegisterAggregate()`
- `ApplicationConfigurer.RegisterProcess()`
- `ApplicationConfigurer.RegisterIntegration()`
- `ApplicationConfigurer.RegisterProjection()`
- `CommandExecutor.ExecuteCommand()`
- `HandlesCommand()`
- `ExecutesCommand()`
- `HandlesEvent()`
- `RecordsEvent()`
- `SchedulesTimeout()`

### Removed

Expand Down
32 changes: 17 additions & 15 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,20 @@ type ApplicationConfigurer interface {
RegisterProjection(ProjectionMessageHandler, ...RegisterProjectionOption)
}

// RegisterAggregateOption is an option that affects the behavior of a call to
// the RegisterAggregate() method of the [ApplicationConfigurer] interface.
type RegisterAggregateOption struct{}

// RegisterProcessOption is an option that affects the behavior of a call to
// the RegisterProcess() method of the [ApplicationConfigurer] interface.
type RegisterProcessOption struct{}

// RegisterIntegrationOption is an option that affects the behavior of a call to
// the RegisterIntegration() method of the [ApplicationConfigurer] interface.
type RegisterIntegrationOption struct{}

// RegisterProjectionOption is an option that affects the behavior of a call to
// the RegisterProjection() method of the [ApplicationConfigurer] interface.
type RegisterProjectionOption struct{}
type (
// RegisterAggregateOption is an option that affects the behavior of a call to
// the RegisterAggregate() method of the [ApplicationConfigurer] interface.
RegisterAggregateOption struct{}

// RegisterProcessOption is an option that affects the behavior of a call to
// the RegisterProcess() method of the [ApplicationConfigurer] interface.
RegisterProcessOption struct{}

// RegisterIntegrationOption is an option that affects the behavior of a call to
// the RegisterIntegration() method of the [ApplicationConfigurer] interface.
RegisterIntegrationOption struct{}

// RegisterProjectionOption is an option that affects the behavior of a call to
// the RegisterProjection() method of the [ApplicationConfigurer] interface.
RegisterProjectionOption struct{}
)
32 changes: 27 additions & 5 deletions route.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "reflect"
// [IntegrationConfigurer].
//
// An application MUST NOT route a single command type to more than one handler.
func HandlesCommand[T Command]() HandlesCommandRoute {
func HandlesCommand[T Command](...HandlesCommandOption) HandlesCommandRoute {
return HandlesCommandRoute{typeOf[T]()}
}

Expand All @@ -20,7 +20,7 @@ func HandlesCommand[T Command]() HandlesCommandRoute {
// [IntegrationConfigurer].
//
// An application MUST NOT route a single event type from more than one handler.
func RecordsEvent[T Event]() RecordsEventRoute {
func RecordsEvent[T Event](...RecordsEventOption) RecordsEventRoute {
return RecordsEventRoute{typeOf[T]()}
}

Expand All @@ -29,15 +29,15 @@ func RecordsEvent[T Event]() RecordsEventRoute {
//
// It's used as an argument to the Routes() method of [ProcessConfigurer] or
// [ProjectionConfigurer].
func HandlesEvent[T Event]() HandlesEventRoute {
func HandlesEvent[T Event](...HandlesEventOption) HandlesEventRoute {
return HandlesEventRoute{typeOf[T]()}
}

// ExecutesCommand routes command messages produced by a
// [ProcessMessageHandler].
//
// It's used as an argument to the Routes() method of [ProcessConfigurer].
func ExecutesCommand[T Command]() ExecutesCommandRoute {
func ExecutesCommand[T Command](...ExecutesCommandOption) ExecutesCommandRoute {
return ExecutesCommandRoute{typeOf[T]()}
}

Expand All @@ -47,7 +47,7 @@ func ExecutesCommand[T Command]() ExecutesCommandRoute {
// It's used as an argument to the Routes() method of [ProcessConfigurer].
//
// An application MAY use a single timeout type with more than one process.
func SchedulesTimeout[T Timeout]() SchedulesTimeoutRoute {
func SchedulesTimeout[T Timeout](...SchedulesTimeoutOption) SchedulesTimeoutRoute {
return SchedulesTimeoutRoute{typeOf[T]()}
}

Expand Down Expand Up @@ -85,3 +85,25 @@ func (SchedulesTimeoutRoute) isRoute() {}
func typeOf[T any]() reflect.Type {
return reflect.TypeOf((*T)(nil)).Elem()
}

type (
// HandlesCommandOption is an option that affects the behavior of the route
// returned by [HandlesCommand].
HandlesCommandOption struct{}

// ExecutesCommandOption is an option that affects the behavior of the route
// returned by [ExecutesCommand].
ExecutesCommandOption struct{}

// HandlesEventOption is an option that affects the behavior of the route
// returned by [HandlesEvent].
HandlesEventOption struct{}

// RecordsEventOption is an option that affects the behavior of the route
// returned by [RecordsEvent].
RecordsEventOption struct{}

// SchedulesTimeoutOption is an option that affects the behavior of the
// route returned by [SchedulesTimeout].
SchedulesTimeoutOption struct{}
)

0 comments on commit 88cba77

Please sign in to comment.