Genocs.Core Agent Reference

This document is optimized for AI-assisted development sessions.

Genocs.Core Agent Reference

Purpose

This document is optimized for AI-assisted development sessions. It prioritizes fast retrieval of:

  • What Genocs.Core is responsible for
  • Which APIs to call for specific goals
  • Where source of truth lives
  • What constraints and runtime behaviors matter

Quick Facts

KeyValue
PackageGenocs.Core
Project filesrc/Genocs.Core/Genocs.Core.csproj
Target frameworksnet10.0, net9.0, net8.0
Primary roleRuntime implementation layer for Genocs.Common abstractions
Core themesBuilder bootstrap, CQRS dispatching, Domain primitives, Repository abstractions, Auditing, Utilities

Use This Package When

  • You need a consistent app bootstrap flow with startup initializers.
  • You want in-memory command, query, and event dispatching via DI.
  • You need base Entity and AggregateRoot classes for DDD-style modeling.
  • You need repository abstractions and a generic repository base implementation.
  • You need shared extension utilities used across Genocs packages.

Do Not Assume

  • This package does not provide external message broker transport by itself.
  • Handler auto-registration only works for assemblies currently loaded into AppDomain.
  • The WebApplication overload of MapDefaultEndpoints is Development-only.

High-Value Entry Points

Builder and startup

CQRS registration and dispatch

Domain model primitives

Repository and data access abstractions

Auditing

Utilities

Decision Matrix For Agents

GoalPreferred APINotes
Bootstrap a serviceAddGenocs on WebApplicationBuilderCreates IGenocsBuilder and applies core setup
Run startup tasksAddInitializer / AddInitializer then UseGenocsUseGenocs executes registered initializers
Register CQRS handlers by conventionAddHandlers(projectName)Filters loaded assemblies by name match
Register command/query/event handlers separatelyAddCommandHandlers, AddQueryHandlers, AddEventHandlersScans loaded assemblies for handler interfaces
Register in-memory dispatchersAddDispatchers or AddInMemory*Dispatcher methodsDispatchers are singleton services
Add standard health/root endpointsMapDefaultEndpointsWebApplication overload gated to Development
Model domain aggregatesAggregateRoot and DomainEventDomainEvents list is on AggregateRoot
Build custom repositoryInherit RepositoryBase<TEntity, TKey>Override persistence-specific operations

Minimal Integration Recipe

Install

dotnet add package Genocs.Core

Setup in Program.cs

using Genocs.Core.Builders;
using Genocs.Core.CQRS.Commons;

var builder = WebApplication.CreateBuilder(args);

IGenocsBuilder genocs = builder.AddGenocs();

builder.Services
    .AddDispatchers()
    .AddHandlers("MyService");

// Optional startup initializer
// genocs.AddInitializer<MyInitializer>();

genocs.Build();

var app = builder.Build();

app.UseGenocs();
app.MapDefaultEndpoints();

app.Run();

Behavior Notes That Affect Agent Decisions

  • AddHandlers(projectName) and the Add*Handlers methods rely on AppDomain.CurrentDomain.GetAssemblies().
  • Command and event dispatchers create async scopes and resolve handlers per call.
  • QueryDispatcher has two query paths: one reflection-based for IQuery, one generic path for TQuery.
  • MapDefaultEndpoints(WebApplication) exits early outside Development.
  • UseGenocs runs initializer execution synchronously from startup flow.

Source-Accurate Capability Map

Builder capabilities

  • Exposes DI and configuration through IGenocsBuilder
  • Supports duplicate registration protection via TryRegister
  • Supports deferred build actions via AddBuildAction
  • Supports explicit startup initializer registration

Files:

CQRS capabilities

  • Registers command/query/event handlers via assembly scanning
  • Dispatches commands to ICommandHandler
  • Dispatches queries to IQueryHandler<TQuery, TResult>
  • Publishes events to all matching IEventHandler
  • Provides an aggregate IDispatcher for command/query/event APIs

Files:

Domain capabilities

  • Identity and equality semantics through Entity base classes
  • Aggregate roots with DomainEvents collection
  • Domain event base type and created/updated/deleted wrappers
  • Soft-delete convenience extensions and entity-not-found exception

Files:

Repository capabilities

  • Ardalis.Specification-compatible repository abstractions
  • Dapper query interfaces for read scenarios
  • Generic repository base with common sync/async orchestration
  • Optional mapping attributes for repository conventions

Files:

Auditing capabilities

  • Base classes for creation/modification/full-audited entities
  • Helper methods to set creator and modifier values
  • Trail model for audit history shape

Files:

Utility capabilities

  • Collection helpers including topological dependency sort
  • String, object, and exception helper methods
  • RSA key XML import/export helpers

Files:

Dependencies

From src/Genocs.Core/Genocs.Core.csproj:

  • Genocs.Common
  • Spectre.Console
  • Ardalis.Specification
  • MediatR.Contracts
  • Scrutor
  • Microsoft.AspNetCore.App framework reference