-
Notifications
You must be signed in to change notification settings - Fork 8
Can we refactor events? #214
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
Comments
🙏 Thank you @mmmoli for your feedback and for appreciating my work!I'm truly glad that you find value in the 📌 Example Project Using
|
Makes total sense. Thank you. But how does this work in a serverless setup?
|
In a serverless setup, the ✅ Recommended ApproachInstead of relying on in-memory event handling, use a persistent event-driven mechanism like:
How to Adapt?Instead of import { EventBridgeClient, PutEventsCommand } from "@aws-sdk/client-eventbridge";
const eventBridge = new EventBridgeClient({ region: "us-east-1" });
context.subscribe('Invoice:GenerateInvoice', async (args) => {
await eventBridge.send(new PutEventsCommand({
Entries: [{
Source: "myApp",
DetailType: "InvoiceGenerated",
Detail: JSON.stringify(args.detail),
EventBusName: "default"
}]
}));
}); This ensures the event persists beyond the Lambda execution lifecycle. 🚀 |
You know how much I love this lib… ❤
From the Docs:
My understanding
Complexity
Dispatching the event requires some infrastructure: My Event Bus.
I don't want to add this in the domain layer – bad practice.
What I think I want, is:
Problem
The docs describe this round the opposite way, no?
Things I've tried
1. Custom Constructor to EventHandler
– Great, but I still can't dispatch without importing my Event Bus.
2. Custom Parameter
API I think we need
In domain layer
– I don't care how it's dispatched here. So I don't care about a "handler".
In UseCase
– I'm not creating the handler here, I'm just passing it and saying "use this to dispatch the event, thanks!"
And finally, in infra:
and
– All the definitions of things without any understanding or logic as to when this all gets called.
Bonus!
Strict typing of the event args would be 👌🏻
Something like:
The text was updated successfully, but these errors were encountered: