add-integration-event
/add-integration-event
Publish a cross-module integration event via the Outbox and handle it idempotently in another module. Use when one module must react to something that happened in another. See .agents/rules/eventing.md.
- Author
- fullstackhero ↗
- Repository
- dotnet-starter-kit ↗
- Licence
- MIT
- Last repository change
- 09.10.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 09.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Publish a cross-module integration event via the Outbox and handle it idempotently in another module. Use when one module must react to something that happened in another. See .agents/rules/eventing.md.
Arguments
/add-integration-event [SourceModule] [EventName] [ConsumerModule]
Original author description
Publish a cross-module integration event via the Outbox and handle it idempotently in another module. Use when one module must react to something that happened in another. See .agents/rules/eventing.md.
How it works
- Step 1 — Define the event (source module's Contracts)
- Step 2 — Publish via the Outbox (source handler)
- Step 3 — Handle it (consumer module)
- Gotchas
- Checklist
SKILL.md preview
---
name: add-integration-event
description: Publish a cross-module integration event via the Outbox and handle it idempotently in another module. Use when one module must react to something that happened in another. See .agents/rules/eventing.md.
argument-hint: "[SourceModule] [EventName] [ConsumerModule]"
---
# Add Integration Event
Cross-module communication goes through **integration events + the Outbox** (transactional, crash-safe) —
never a direct in-process call into another module's runtime, and never `IEventBus.PublishAsync` from a
handler. Full model: `.agents/rules/eventing.md`.
## Step 1 — Define the event (source module's Contracts)
`Modules.{Source}.Contracts/Events/{Event}IntegrationEvent.cs` — implement `IIntegrationEvent`:
```csharp
public sealed record {Event}IntegrationEvent(
Guid Id,
DateTime OccurredOnUtc,
string? TenantId,
string CorrelationId,
string Source,
Guid {Entity}Id,
string SomePayload) : IIntegrationEvent;
```
⚠️ Don't rename/move this type later — the outbox stores its assembly-qualified name; a rename makes
`Type.GetType()` return null and the message dead-letters. Keep the type name + namespace stable.
## Step 2 — Publish via the Outbox (source handler)
Publishing needs **no module registration** — the outbox is framework-owned and the host wires it once. Inject `IOutboxWriter` (from `FSH.Framework.Eventing.Abstractions`) and add the event in the same unit of work:
```csharp
public sealed class Do{Thing}CommandHandler({Source}DbContext db, IOutboxWriter outbox)
: ICommandHandler<Do{Thing}Command, Unit>
{
public async ValueTask<Unit> Handle(Do{Thing}Command command, CancellationToken cancellationToken)
{
// … mutate entities, db.SaveChangesAsync …
var evt = new {Event}IntegrationEvent(
Id: Guid.CreateVersion7(),
OccurredOnUtc: DateTime.UtcNow,
TenantId: /* current tenant */,
CorrelationId: Guid.NewGuid().ToString(),
Source: "{Source}",
{Entity}Id: entity.Id,
SomePayload: "…");
await outbox.AddAsync(evt, cancellationToken).ConfigureAwait(false);
return Unit.Value;
}
}
```
The `OutboxDispatcherHostedService` later publishes it via `IEventBus`.
## Step 3 — Handle it (consumer module)
`Modules.{Consumer}/IntegrationEventHandlers/{Event}IntegrationEventHandler.cs` — `sealed`, implement `IIntegrationEventHandler<T>`:
```csharp
public sealed class {Event}IntegrationEventHandler({Consumer}DbContext db /*, IHubContext<AppHub> hub */)
: IIntegrationEventHandler<{Event}IntegrationEvent>
{
public async Task HandleAsync({Event}IntegrationEvent @event, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(@event);
// … write to the consumer's tables / push a notification …
await db.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
}
}
```
Register the consumer's handlers in its `ConfigureServices`:
```csharp
builder.Services.AddIntegrationEventHandlers(typeof({Consumer}Module).Assembly);
```
## Gotchas
- **Idempotency is free** with the in-memory bus (the Inbox dedups by `{eventId, handlerName}`) — don't hand-roll it.
- The in-memory bus runs handlers **synchronously in the publisher's scope** — keep the handler lean; a throw surfaces to the originating request. Published via the outbox, that scope belongs to the dispatcher, so the consumer runs on the next cycle and its failures never reach the caller. Don't let a caller (or a test) assume the side effect already happened; integration tests drain with `OutboxDrain.DrainAsync`.
- If the handler reads a **tenant-filtered** DbContext from a background path (open-generic handler, Hangfire job), restore Finbuckle context first via `IMultiTenantContextSetter` (see `WebhookFanoutHandler`).
- **Module load order:** the consumer must load before the publisher if it must react (`Order` in `[assembly: FshModule]`) — e.g. Notifications (750) before Chat (800).
## Checklist
- [ ] Event in source Contracts, implements `IIntegrationEvent`, stable type name
- [ ] Published via `IOutboxWriter.AddAsync` (not the bus); no per-module eventing registration needed
- [ ] Consumer handler `sealed : IIntegrationEventHandler<T>`; `AddIntegrationEventHandlers(assembly)` registered
- [ ] Background readers restore tenant context; module `Order` lets the consumer load first
- [ ] Build + tests green
Versions
The database has no other skills named add-integration-event.
Database snapshot: 13.11.2026 · package version 3469820a99ac (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Similar skills
- 100new-event
Add a new domain event end to end - versioned schema in contracts/, outbox-based producer, idempotent consumer, contract test and docs. Use when the user asks to add, publish or consume a new event (security.*, user.*, role.*). - 90integration-doc-maintainer
Maintains cross-module integration documentation. Use when a request affects published or consumed events, background jobs, external service contracts or any cross-module dependency. - 100integration-architecture
This skill should be used when the user asks about "messaging patterns", "command vs event", "push vs pull", "message reliability", "at-least-once delivery", "idempotency", "transactional outbox", "saga pattern", "fire and forget", "retry strategy", "event-driven architecture",… - 100messaging
Asynchronous messaging patterns for .NET applications. Covers Wolverine and MassTransit, outbox pattern, saga and choreography, and broker configuration for RabbitMQ and Azure Service Bus. Load this skill when implementing event-driven communication, background processing,… - 100design-module-and-service-communication
Decide how two ABP modules or microservices communicate — synchronous integration services vs asynchronous distributed events — and make events reliable and idempotent. USE FOR: choosing sync (integration services — in-process DI in a monolith, HTTP client proxy across… - 100ts-ddd-events
ACTIVATE when implementing domain events, event store, outbox pattern, or reliable event publishing in TypeScript. ACTIVATE for 'domain event', 'outbox', 'event store', 'event-driven', 'reliable publishing'. Covers: domain event structure and naming, event store (append-only),…