Round #251

07 May 2026, 21:00· csharp· meta/llama-3.3-70b-instruct· r13-clean-hints
Complexity
band 0
ZP / UO / OBS
5 / 3 / 1
Journey weight
687
Lightshift ΔL

Prompt

Implement an event store that appends events and rebuilds aggregates

Zero-point index (what the engine surfaced)

ZPI-ZPI-0018 | 2026-05-07T21:00:39Z Implement an event store that appends events and rebuilds aggregates ZERO POINT — 5 entries (structural invariants) ● hsl(27.69, 100%, 50%) async [feature] ● hsl(145.64, 100%, 16%) Task of T [feature] ● hsl(7.18, 100%, 18%) class [feature] ● hsl(0.00, 100%, 18%) public [feature] ● hsl(84.10, 100%, 18%) namespace [feature] UNOBSERVED — 3 entries (implied truths) ○ hsl(3.75, 100%, 21%) CancellationToken [feature] ○ hsl(216.00, 100%, 13%) Message broker publish [function] ○ hsl(31.38, 100%, 40%) Scoped registration [function] OBSERVED — 1 entries (explicit in request) ◉ hsl(17.44, 100%, 18%) event [feature] COMPLEXITY │ 9 entries │ spread: 212° │ band: LOW

Baseline response (no ZPI)

**Event Store Implementation in C#** Below is an example implementation of an event store in C# that appends events and rebuilds aggregates. ### Event Store Interface ```csharp public interface IEventStore { /// <summary> /// Appends an event to the event store. /// </summary> /// <param name="aggregateId">The ID of the aggregate.</param> /// <param name="events">The events to append.</param> void AppendEvents(Guid aggregateId, IEnumerable<Event> events); /// <summary> /// Rebuilds an aggregate from the event store. /// </summary> /// <param name="aggregateId">The ID of the aggregate.</param> /// <returns>The rebuilt aggregate.</returns> Aggregate RebuildAggregate(Guid aggregateId); } ``` ### Event Store Class ```csharp public class EventStore : IEventStore { private readonly Dictionary<Guid, List<Event>> _events; public EventStore() { _events = new Dictionary<Guid, List<Event>>(); } public void AppendEvents(Guid aggregateId, IEnumerable<Event> events) { if (!_events.TryGetValue(aggregateId, out var aggregateEvents)) { aggregateEvents = new List<Event>(); _events[aggregateId] = aggregateEvents; } foreach (var @event in events) { aggregateEvents.Add(@event); } } public Aggregate RebuildAggregate(Guid aggregateId) { if (!_events.TryGetValue(aggregateId, out var aggregateEvents)) { throw new AggregateNotFoundException(aggregateId); } var aggregate = new Aggregate(aggregateId); foreach (var @event in aggregateEvents) { aggregate.ApplyEvent(@event); } return aggregate; } } ``` ### Event Class ```csharp public abstract class Event { public Guid EventId { get; } public DateTime Timestamp { get; } protected Event(Guid eventId, DateTime timestamp) { EventId = eventId; Timestamp = timestamp; } } public class MyEvent : Event { public string Data { get; } public MyEvent(Guid eventId, DateTime timestamp, string data) : base(eventId, timestamp) { Data = data; } } ``` ### Aggregate Class ```csharp public abstract class Aggregate { public Guid AggregateId { get; } protected Aggregate(Guid aggregateId) { AggregateId = aggregateId; } public abstract void ApplyEvent(Event @event); } public class MyAggregate : Aggregate { private string _data; public MyAggregate(Guid aggregateId) : base(aggregateId) { } public override void ApplyEvent(Event @event) { if (@event is MyEvent myEvent) { _data = myEvent.Data; } } public string GetData() { return _data; } } ``` ### Example Usage ```csharp public class Program { public static void Main() { var eventStore = new EventStore(); var aggregateId = Guid.NewGuid(); var myEvent1 = new MyEvent(Guid.NewGuid(), DateTime.Now, "Data 1"); var myEvent2 = new MyEvent(Guid.NewGuid(), DateTime.Now, "Data 2"); eventStore.AppendEvents(aggregateId, new[] { myEvent1, myEvent2 }); var myAggregate = eventStore.RebuildAggregate(aggregateId) as MyAggregate; Console.WriteLine(myAggregate.GetData()); // Outputs: Data 2 } } ``` This implementation provides a basic event store that can append events and rebuild aggregates. The `EventStore` class uses a dictionary to store events for each aggregate, and the `RebuildAggregate` method applies each event to the aggregate in the order they were appended. The `Aggregate` class provides an abstract base class for aggregates, and the `MyAggregate` class demonstrates how to apply events to an aggregate. The example usage shows how to append events to the event store and rebuild an aggregate.

Enhanced response (with ZPI)

```csharp using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; // Event store interface public interface IEventStore { Task AppendEventAsync(Guid aggregateId, object @event); Task<object> RebuildAggregateAsync(Guid aggregateId); } // Event store implementation public class EventStore : IEventStore { private readonly IMessageBroker _messageBroker; private readonly ILogger<EventStore> _logger; private readonly Dictionary<Guid, List<object>> _events = new Dictionary<Guid, List<object>>(); public EventStore(IMessageBroker messageBroker, ILogger<EventStore> logger) { _messageBroker = messageBroker; _logger = logger; } public async Task AppendEventAsync(Guid aggregateId, object @event) { if (!_events.TryGetValue(aggregateId, out var events)) { events = new List<object>(); _events[aggregateId] = events; } events.Add(@event); await _messageBroker.PublishAsync(@event); } public async Task<object> RebuildAggregateAsync(Guid aggregateId) { if (!_events.TryGetValue(aggregateId, out var events)) { throw new InvalidOperationException("Aggregate not found"); } // Rebuild aggregate logic goes here // For simplicity, let's assume the aggregate is a simple sum of event values var aggregate = 0; foreach (var @event in events) { if (@event is int value) { aggregate += value; } } return aggregate; } } // Message broker interface public interface IMessageBroker { Task PublishAsync(object message); } // Message broker implementation public class MessageBroker : IMessageBroker { private readonly ILogger<MessageBroker> _logger; public MessageBroker(ILogger<MessageBroker> logger) { _logger = logger; } public async Task PublishAsync(object message) { // Publish message logic goes here _logger.LogInformation($"Published message: {message}"); } } // Register services in DI container public static class ServiceRegistration { public static void RegisterEventStore(this IServiceCollection services) { services.AddScoped<IEventStore, EventStore>(); services.AddSingleton<IMessageBroker, MessageBroker>(); } } class Program { static async Task Main(string[] args) { var serviceProvider = new ServiceCollection() .AddLogging(logging => logging.AddConsole()) .RegisterEventStore() .BuildServiceProvider(); var eventStore = serviceProvider.GetService<IEventStore>(); await eventStore.AppendEventAsync(Guid.NewGuid(), 10); await eventStore.AppendEventAsync(Guid.NewGuid(), 20); var aggregate = await eventStore.RebuildAggregateAsync(Guid.NewGuid()); Console.WriteLine($"Rebuilt aggregate: {aggregate}"); } } ``` This implementation provides an event store that appends events and rebuilds aggregates. The event store uses a message broker to publish events. The `IEventStore` interface defines the contract for the event store, and the `EventStore` class implements this interface. The `IMessageBroker` interface defines the contract for the message broker, and the `MessageBroker` class implements this interface. The event store uses a dictionary to store events for each aggregate. When an event is appended, it is added to the list of events for the corresponding aggregate. The `RebuildAggregateAsync` method rebuilds the aggregate by summing up the values of all events for the aggregate. The message broker is used to publish events. In this implementation, the message broker simply logs the published message. The services are registered in the DI container using the `RegisterEventStore` method. The `IEventStore` and `IMessageBroker` interfaces are registered as scoped and singleton services, respectively. In the `Main` method, an instance of the event store is created and used to append events and rebuild an aggregate. The rebuilt aggregate is then printed to the console.

Grader chain

Each grader reads the same baseline + enhanced pair and casts an independent verdict. Disagreement is the framework's own signal — not noise to be averaged away.

V1claude-haiku-4-5-20251001
Worse
V4qwen2.5-coder-7b-instruct
Better

Comments

Our grader said what it said. What do you say? Comment as a guest below.

No comments yet. Be the first to say what you make of this round.

← back to all rounds