Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for handling event/command metadata - application layer #250

Merged
merged 5 commits into from
Nov 25, 2023

Conversation

idugalic
Copy link
Member

@idugalic idugalic commented Nov 17, 2023

  • EventRepository is extended with additional methods to support fetching and storing metadata of the event.

  • StateRepository is extended with additional methods to support fetching and storing metadata.

  • ViewStateRepository is extended with additional methods to support fetching and storing metadata.

  • ActionPublisher is extended with additional methods to support publishing actions with metadata.

  • Metadata is modeled as a Map<String, Any>.

  • Metadata is restricted to the Application layer only. It is a Map. It can be anything/week contract. It does not leak into Domain. All the computations and decisions are done by only using a strong type of the payload/Event/E

Some examples of metadata:

  • userId
  • traceId
  • eventRevision

NOTICE, how userId could be part of the formal Paylod Type/E/C in case authorization is a concern of the Domain core logic. SO, if you don't need these data to make domain core decisions put it in metadata, otherwise, it is part of the strongly typed payload type.

Aggregate/MaterializedView/SagaManager is enriched with new extensions to expose the handle API that can accept metadata as an additional parameter:

fun <C, S, E> EventSourcingAggregate<C, S, E>.handle(command: C): Flow<E> =
    command
        .fetchEvents()
        .computeNewEvents(command)
        .save()


fun <C, S, E> EventSourcingAggregate<C, S, E>.handle(
    command: C,
    metaData: Map<String, Any>
): Flow<Pair<E, Map<String, Any>>> =
    command
        .fetchEventsAndMetaData().map { it.first }
        .computeNewEvents(command)
        .saveWithMetaData(metaData)

This PR is not binary backwards compatible with previous version!

@idugalic idugalic changed the title Support for handling event/command metadata - event sourcing aggregate Support for handling event/command metadata - application layer Nov 18, 2023
@idugalic idugalic merged commit d26c03b into main Nov 25, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant