Open
Conversation
…nd repo patterns Introduces a generic typeRegistry[K, F] to replace four near-identical mutex/map/panic implementations across command, event, aggregate, and snapshot registries. Also adds generic helpers for middleware chaining, context value extraction, and recursive repo unwrapping. All public API signatures remain unchanged.
Adds type-parameterized registration functions that eliminate factory closures at call sites: eh.RegisterCommandType[MyCommand]() eh.RegisterEventDataType[MyEventData](MyEventType) The existing factory-based RegisterCommand and RegisterEventData remain unchanged for backward compatibility. Aggregates still require the factory approach due to UUID-dependent construction.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Use Go generics to deduplicate four near-identical internal patterns while keeping all public API signatures unchanged. Also adds generic registration alternatives for commands and event data.
Affected Components
Related Issues
None
Solution and Design
typeRegistry[K, F]replaces four copy-pasted mutex/map/panic registry implementations incommand.go,event.go,aggregate.go, andsnapshot.go.applyMiddleware[H, M]deduplicatesUseCommandHandlerMiddlewareandUseEventHandlerMiddleware.fromContext[T]simplifies context value extraction to one-liners.IntoRepo[T]eliminates recursive repo unwrapping duplication acrossrepo/cache,repo/version, andtracing.RegisterCommandType[T]()andRegisterEventDataType[T](eventType)provide generic alternatives that eliminate factory closures:All internal changes are backward compatible. No exported type signatures changed.
Steps to test and verify
go build ./...— all packages compilego vet ./...— no new issuesgo test ./...— all existing tests pass, new generic registration tests includedCloses #405