Created
December 3, 2022 05:52
-
-
Save leegilmorecode/58c060a5e5d3755e6ce3adb7ffd326f7 to your computer and use it in GitHub Desktop.
Example repository for publishing domain events via a secondary adapter
This file contains 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
import { DomainEvent } from '@entity/domain-event'; | |
import { publishEvent } from '@adapters/secondary/event-adapter'; | |
// this is the repository which the domain calls to utilise the adapter | |
// only working with domain entities, and translating dto's from the secondary adapters | |
// domain --> (repository) --> adapter | |
export async function publishDomainEvents( | |
events: DomainEvent[] | |
): Promise<void> { | |
const eventsToPublish: Promise<void>[] = events.map((item) => | |
publishEvent( | |
item.event, | |
item.eventName, | |
item.source, | |
item.eventVersion, | |
item.eventDateTime | |
) | |
); | |
await Promise.all(eventsToPublish); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment