Skip to content
Back to skills

Add Event Handler

ASecurity

Scaffold a WolverineFx event handler for domain events or integration events. Use whenever the user wants to react to domain events, publish messages, send notifications, update read models, or add async side effects.

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 11, 2026
developmentbashreactapibackend

Works with

  • api
  • mcp

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add makigjuro/cloud-app-blueprint --skill add-event-handler --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Add Event Handler?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Add Event Handler
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/makigjuro-add-event-handler/badge)](https://www.skillsdirectory.com/skills/makigjuro-add-event-handler)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: add-event-handler
description: Scaffold a WolverineFx event handler for domain events or integration events. Use whenever the user wants to react to domain events, publish messages, send notifications, update read models, or add async side effects.
allowed-tools: Read, Write, Edit, Glob, Grep, Bash, mcp__plugin_dotnet-architect_context7__resolve-library-id, mcp__plugin_dotnet-architect_context7__query-docs
user-invocable: true
argument-hint: "{EventName} [Service]"
---

# Add Event Handler

When the user asks to add an event handler, scaffold a WolverineFx handler for a domain or integration event.

## Arguments

- `{EventName}` -- Name of the event to handle (e.g., `OrderCreatedEvent`)
- `{Service}` -- Target microservice (ask if ambiguous)

## Configuration

Read `blueprint.json` from the project root at the start of execution. Extract:
- `NAMESPACE` = `project.namespace` (default: detect from `*.sln` name or first `*.csproj` root namespace)
- `DOMAIN_PATH` = `backend.sharedDomainPath` (default: find directory matching `**/Domain/` containing `Entities/`)
- `SERVICES` = `backend.services[]` (default: discover from `src/*/` directories containing `.Application/` subfolders)
- `PUBLISHER_INTERFACE` = `backend.messagingConventions.publisherInterface` (default: `IMessagePublisher` — but grep the codebase for the actual publisher abstraction first; projects often name it after their broker, e.g. `INatsPublisher`)
- `SUBJECT_PREFIX` = `backend.messagingConventions.subjectPrefix` (used to build subject/topic names consistent with the project's hierarchy)

If `blueprint.json` does not exist, auto-detect by scanning the project structure.

## 1. Find the Event

Search for the event class:
```bash
grep -rn "class {EventName}" src/
```

If the event doesn't exist, suggest running `/add-entity` first or create it inline.

## 2. Event Handler (`Application/Events/{EventName}Handler.cs`)

```csharp
namespace {Namespace}.{Service}.Application.Events;

public class {EventName}Handler
{
    // Constructor-inject repositories, services, or ILogger<T>

    public async Task Handle({EventName} @event, CancellationToken cancellationToken)
    {
        // React to the event:
        // - Update read models
        // - Send notifications
        // - Publish integration events
        // - Trigger side effects
    }
}
```

For handlers that publish to a message broker:

```csharp
public class {EventName}Handler
{
    private readonly {PUBLISHER_INTERFACE} _messagePublisher;
    private readonly ILogger<{EventName}Handler> _logger;

    public {EventName}Handler({PUBLISHER_INTERFACE} messagePublisher, ILogger<{EventName}Handler> logger)
    {
        _messagePublisher = messagePublisher;
        _logger = logger;
    }

    public async Task Handle({EventName} @event, CancellationToken cancellationToken)
    {
        _logger.LogInformation("Handling {Event} for {Id}", nameof({EventName}), @event.Id);

        await _messagePublisher.PublishAsync(
            "{domain}.events.{event-type}",
            @event,
            cancellationToken);
    }
}
```

## 3. Integration Event (if cross-service)

If the handler needs to publish an event for other services:

```csharp
namespace {Namespace}.{Service}.Application.Events;

public record {Name}IntegrationEvent(
    Guid Id,
    // relevant fields
    DateTimeOffset OccurredAt);
```

## Checklist

- [ ] Handler class in `Application/Events/` folder
- [ ] Event parameter named `@event` (reserved keyword escaping)
- [ ] CancellationToken propagated
- [ ] Logging at appropriate level
- [ ] No return value (event handlers are fire-and-forget)
- [ ] Idempotent handling (events may be delivered more than once)
- [ ] No exceptions thrown for business logic (log and continue)

## Guidelines

- WolverineFx discovers handlers by convention (class name ending in `Handler`/`Consumer`, `Handle` method) -- but only in assemblies it scans. Handlers in the Application project need `options.Discovery.IncludeAssembly(typeof({EventName}Handler).Assembly)` in `builder.Host.UseWolverine(...)` (check it is already there)
- WolverineFx 6 generates handler code at runtime and needs the `WolverineFx.RuntimeCompilation` package referenced by the Host (alongside `WolverineFx`, same version in `Directory.Packages.props`); without it (and without pre-generated code) handler dispatch fails at runtime
- One handler per event per concern (don't mix read model updates with notifications)
- Use `ILogger` for observability, not `Console.WriteLine`
- For message broker subjects/topics, follow the project's naming conventions

## Output

After scaffolding, report:
```
## Scaffolded: {EventName}Handler

Files created:
- `src/{Service}/{Service}.Application/Events/{EventName}Handler.cs`
{if integration event:}
- `src/{Service}/{Service}.Application/Events/{Name}IntegrationEvent.cs`

Next: Run `/run-tests` to verify handler registration.
```

## Error Handling

- **Event class not found:** Suggest running `/add-entity` first to create the entity and its domain events.
- **Message publisher interface missing:** Check if `{PUBLISHER_INTERFACE}` is registered in the service's DI. If not, it may need to be added to the Infrastructure layer.

## Related Skills

- `/add-entity` to create the domain entity and events first
- `/add-command` if the handler needs to trigger a command

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.