ronnythedev/dotnet-clean-architecture-skills/09-dotnet-domain-events-generator

Claude Code and agent skill by ronnythedev/dotnet-clean-architecture-skills

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Generates Domain Events and their handlers following DDD patterns. Implements event raising in entities, MediatR notification handlers, and the Outbox pattern for reliable event processing.

Install

npx vskill@latest install ronnythedev/dotnet-clean-architecture-skills/09-dotnet-domain-events-generator

SKILL.md

Domain Events Generator

Overview

Domain Events capture something significant that happened in the domain:

  • Raised by entities - When state changes occur
  • Handled by notification handlers - React to events
  • Outbox pattern - Reliable event delivery
  • Decoupled - Publisher doesn't know subscribers

Quick Reference

ComponentPurposeLocation
IDomainEventMarker interfaceDomain/Abstractions
{Entity}{Action}DomainEventEvent recordDomain/{Aggregate}/Events
{Event}DomainEventHandlerEvent handlerApplication/{Feature}
OutboxMessagePersisted eventInfrastructure/Outbox

Event Structure

/Domain/
├── Abstractions/
│ └── IDomainEvent.cs
└── {Aggregate}/
└── Events/
├── {Entity}CreatedDomainEvent.cs
├── {Entity}UpdatedDomainEvent.cs
└── ...
/Application/
└── {Feature}/
└── EventHandlers/
├── {Event}Handler.cs
└── ...
/Infrastructure/
└── Outbox/
├── OutboxMessage.cs
├── OutboxMessageConfiguration.cs
└── ProcessOutboxMessagesJob.cs

Template: Domain Event Interface

csharp
// src/{name}.domain/Abstractions/IDomainEvent.cs
using MediatR;
namespace {name}.domain.abstractions;
/// <summary>
/// Marker interface for domain events.
/// Domain events represent something significant that happened in the domain.
/// </summary>
public interface IDomainEvent : INotification
{
/// <summary>
/// Unique identifier for this event instance
/// </summary>
Guid Id { get; }
/// <summary>
/// When the event occurred
/// </summary>
DateTime OccurredOnUtc { get; }
}

Template: Base Domain Event Record

csharp
// src/{name}.domain/Abstractions/DomainEvent.cs
namespace {name}.domain.abstractions;
/// <summary>
/// Base record for domain events with common properties
/// </summary>
public abstract record DomainEvent : IDomainEvent
{
public Guid Id { get; init; } = Guid.NewGuid();
public DateTime OccurredOnUtc { get; init; } = DateTime.UtcNow;
}

Template: Specific Domain Events

csharp
// src/{name}.domain/{Aggregate}/Events/{Entity}CreatedDomainEvent.cs
using {name}.domain.abstractions;
namespace {name}.domain.{aggregate}.events;
/// <summary>
/// Raised when a new {Entity} is created
/// </summary>
public sealed record {Entity}CreatedDomainEvent(
Guid {Entity}Id) : DomainEvent;
// src/{name}.domain/{Aggregate}/Events/{Entity}UpdatedDomainEvent.cs
/// <summary>
/// Raised when a {Entity} is updated
/// </summary>
public sealed record {Entity}UpdatedDomainEvent(
Guid {Entity}Id,
string PropertyName,
string? OldValue,
string? NewValue) : DomainEvent;
// src/{name}.domain/{Aggregate}/Events/{Entity}DeactivatedDomainEvent.cs
/// <summary>
/// Raised when a {Entity} is deactivated
/// </summary>
public sealed record {Entity}DeactivatedDomainEvent(
Guid {Entity}Id,
string Reason) : DomainEvent;
// src/{name}.domain/{Aggregate}/Events/{Entity}DeletedDomainEvent.cs
/// <summary>
/// Raised when a {Entity} is deleted
/// </summary>
public sealed record {Entity}DeletedDomainEvent(
Guid {Entity}Id) : DomainEvent;

Template: Rich Domain Events

csharp
// src/{name}.domain/Users/Events/UserRegisteredDomainEvent.cs
using {name}.domain.abstractions;
namespace {name}.domain.users.events;
/// <summary>
/// Raised when a new user registers
/// </summary>
public sealed record UserRegisteredDomainEvent : DomainEvent
{
public Guid UserId { get; init; }
public string Email { get; init; } = string.Empty;
public string Name { get; init; } = string.Empty;
public Guid OrganizationId { get; init; }
public UserRegisteredDomainEvent(
Guid userId,
string email,
string name,
Guid organizationId)
{
UserId = userId;
Email = email;
Name = name;
OrganizationId = organizationId;
}
}
// src/{name}.domain/Assessments/Events/AssessmentCompletedDomainEvent.cs
/// <summary>
/// Raised when a user completes an assessment
/// </summary>
public sealed record AssessmentCompletedDomainEvent : DomainEvent
{
public Guid AssessmentId { get; init; }
public Guid UserId { get; init; }
public Guid OrganizationId { get; init; }
public string AssessmentType { get; init; } = string.Empty;
public decimal Score { get; init; }
public DateTime CompletedAt { get; init; }
public AssessmentCompletedDomainEvent(
Guid assessmentId,
Guid userId,
Guid organizationId,
string assessmentType,
decimal score,
DateTime completedAt)
{
AssessmentId = assessmentId;
UserId = userId;
OrganizationId = organizationId;
AssessmentType = assessmentType;
Score = score;
CompletedAt = completedAt;
}
}

Template: Raising Events in Entity

csharp
// src/{name}.domain/{Aggregate}/{Entity}.cs
using {name}.domain.abstractions;
using {name}.domain.{aggregate}.events;
namespace {name}.domain.{aggregate};
public sealed class {Entity} : Entity
{
// ... properties
private {Entity}(
Guid id,
string name,
Guid organizationId,
DateTime createdAt)
: base(id)
{
Name = name;
OrganizationId = organizationId;
CreatedAt = createdAt;
}
/// <summary>
/// Factory method - raises Created event
/// </summary>
public static Result<{Entity}> Create(
string name,
Guid organizationId,
DateTime createdAt)
{
// Validation...
var {entity} = new {Entity}(
Guid.NewGuid(),
name,
organizationId,
createdAt);
// Raise domain event
{entity}.RaiseDomainEvent(new {Entity}CreatedDomainEvent({entity}.Id));
return {entity};
}
/// <summary>
/// Update method - raises Updated event
/// </summary>
public Result Update(string name, DateTime updatedAt)
{
if (string.IsNullOrWhiteSpace(name))
{
return Result.Failure({Entity}Errors.NameRequired);
}
var oldName = Name;
Name = name;
UpdatedAt = updatedAt;
// Raise domain event with change details
RaiseDomainEvent(new {Entity}UpdatedDomainEvent(
Id,
nameof(Name),
oldName,
name));
return Result.Success();
}
/// <summary>
/// Deactivate method - raises Deactivated event
/// </summary>
public Result Deactivate(string reason, DateTime deactivatedAt)
{
if (!IsActive)
{
return Result.Failure({Entity}Errors.AlreadyDeactivated);
}
IsActive = false;
UpdatedAt = deactivatedAt;
RaiseDomainEvent(new {Entity}DeactivatedDomainEvent(Id, reason));
return Result.Success();
}
}

Template: Domain Event Handler

csharp
// src/{name}.application/{Feature}/EventHandlers/{Entity}CreatedDomainEventHandler.cs
using MediatR;
using Microsoft.Extensions.Logging;
using {name}.domain.{aggregate}.events;
namespace {name}.application.{feature}.eventhandlers;
/// <summary>
/// Handles {Entity}CreatedDomainEvent
/// </summary>
internal sealed class {Entity}CreatedDomainEventHandler
: INotificationHandler<{Entity}CreatedDomainEvent>
{
private readonly ILogger<{Entity}CreatedDomainEventHandler> _logger;
public {Entity}CreatedDomainEventHandler(
ILogger<{Entity}CreatedDomainEventHandler> logger)
{
_logger = logger;
}
public Task Handle(
{Entity}CreatedDomainEvent notification,
CancellationToken cancellationToken)
{
_logger.LogInformation(
"{Entity} created: {EntityId} at {OccurredOn}",
notification.{Entity}Id,
notification.OccurredOnUtc);
// Add any side effects here:
// - Send notifications
// - Update read models
// - Trigger workflows
// - Publish to external systems
return Task.CompletedTask;
}
}

Template: Event Handler with Side Effects

csharp
// src/{name}.application/Users/EventHandlers/UserRegisteredDomainEventHandler.cs
using MediatR;
using Microsoft.Extensions.Logging;
using {name}.application.abstractions.email;
using {name}.domain.users.events;
namespace {name}.application.users.eventhandlers;
/// <summary>
/// Sends welcome email when user registers
/// </summary>
internal sealed class UserRegisteredSendWelcomeEmailHandler
: INotificationHandler<UserRegisteredDomainEvent>
{
private readonly IEmailService _emailService;
private readonly ILogger<UserRegisteredSendWelcomeEmailHandler> _logger;
public UserRegisteredSendWelcomeEmailHandler(
IEmailService emailService,
ILogger<UserRegisteredSendWelcomeEmailHandler> logger)
{
_emailService = emailService;
_logger = logger;
}
public async Task Handle(
UserRegisteredDomainEvent notification,
CancellationToken cancellationToken)
{
_logger.LogInformation(
"Sending welcome email to user {UserId}",
notification.UserId);
await _emailService.SendWelcomeEmailAsync(
notification.Email,
notification.Name,
cancellationToken);
}
}
/// <summary>
/// Creates default settings when user registers
/// </summary>
internal sealed class UserRegisteredCreateDefaultSettingsHandler
: INotificationHandler<UserRegisteredDomainEvent>
{
private readonly IUserSettingsRepository _settingsRepository;
private readonly IUnitOfWork _unitOfWork;
public UserRegisteredCreateDefaultSettingsHandler(
IUserSettingsRepository settingsRepository,
IUnitOfWork unitOfWork)
{
_settingsRepository = settingsRepository;
_unitOfWork = unitOfWork;
}
public async Task Handle(
UserRegisteredDomainEvent notification,
CancellationToken cancellationToken)
{
var settings = UserSettings.CreateDefault(notification.UserId);
_settingsRepository.Add(settings);
await _unitOfWork.SaveChangesAsync(cancellationToken);
}
}

Template: Outbox Pattern Implementation

Outbox Message Entity
csharp
// src/{name}.infrastructure/Outbox/OutboxMessage.cs
namespace {name}.infrastructure.outbox;
/// <summary>
/// Represents a domain event stored for reliable delivery
/// </summary>
public sealed class OutboxMessage
{
public Guid Id { get; set; }
public string Type { get; set; } = string.Empty;
public string Content { get; set; } = string.Empty;
public DateTime OccurredOnUtc { get; set; }
public DateTime? ProcessedOnUtc { get; set; }
public string? Error { get; set; }
}
Outbox Configuration
csharp
// src/{name}.infrastructure/Configurations/OutboxMessageConfiguration.cs
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using {name}.infrastructure.outbox;
namespace {name}.infrastructure.configurations;
internal sealed class OutboxMessageConfiguration
: IEntityTypeConfiguration<OutboxMessage>
{
public void Configure(EntityTypeBuilder<OutboxMessage> builder)
{
builder.ToTable("outbox_message");
builder.HasKey(o => o.Id);
builder.Property(o => o.Type)
.HasMaxLength(500)
.IsRequired();
builder.Property(o => o.Content)
.HasColumnType("jsonb")
.IsRequired();
builder.Property(o => o.OccurredOnUtc)
.IsRequired();
builder.Property(o => o.ProcessedOnUtc);
builder.Property(o => o.Error)
.HasColumnType("text");

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
64
Repository forks
11
7-day trend score
21

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/ronnythedev/dotnet-clean-architecture-skills/09-dotnet-domain-events-generator/badge)](https://verified-skill.com/skills/ronnythedev/dotnet-clean-architecture-skills/09-dotnet-domain-events-generator)

Something wrong with this skill or its page? Tell us.