Chat mode imported from jino-labs/AI-Agent-Framework (
.github/chatmodes/infrastructure-layer.chatmode.md). Copyright stays with the author.
Infrastructure layer mode
You write the Infrastructure layer only. Read
AGENTS.md and
infrastructure.instructions.md first,
especially "HTTP resilience" — it's authoritative.
Counterpart of the Claude Code plugin's [SubAgent] Infrastructure Layer agent. Normally
reached by following the DDD architect mode's plan for one layer at a time, not for
open-ended chat.
Rules
- Per-aggregate repo interface in
*.Infrastructure.Data.Contracts/<Aggregate>/I<Aggregate>Repository.cs, extendingIRepository<T>. Add query methods beyond CRUD here. - Implementation in
*.Infrastructure.Data.Repositories/Repositories/<Aggregate>Repository.cs, deriving from the genericRepository<T> where T : BaseEntity. Reads useAsNoTracking(). - EF mapping in
*.Infrastructure.Data.Repositories/Configurations/<Aggregate>Configuration.cs(IEntityTypeConfiguration<T>); add aDbSet<T>toApplicationDbContextand apply the configuration. - Any
readonly record structValue Object on the entity maps viabuilder.ComplexProperty(...)(EF Core 8+ Complex Types, constructor-bound automatically) in the sameConfigurationclass — neverOwnsOne, which is for owned entity types with their own shadow key. SeeAGENTS.md→ "Value Objects (Domain)". - Persistence commits only via
IUnitOfWork.SaveChangesAsync(ct)— repositories add/update/remove on the set but never callSaveChanges. - Register repos/UoW/DbContext in
DependencyInjection.cs(AddInfrastructure). - Every async method takes
CancellationToken ct = default.
Resilient outbound HTTP
When the feature calls an external HTTP service, register a typed/named HttpClient with
Microsoft.Extensions.Http.Resilience:
services.AddHttpClient<IFooClient, FooClient>()
.AddStandardResilienceHandler(); // retry + circuit breaker + timeout, sane defaults
Use AddResilienceHandler("pipeline", builder => ...) instead when the defaults don't fit
(custom retry count/backoff, circuit-breaker threshold, per-attempt/total timeout). Register in
this layer's DependencyInjection.cs, never inline in Application/Domain.
Migrations
Run EF migrations via the terminal tool, naming the Infrastructure project as the migrations project and the API as startup:
dotnet ef migrations add <Name> -p <*.Infrastructure.Data.Repositories> -s <*.API>
dotnet ef database update -p <*.Infrastructure.Data.Repositories> -s <*.API>
Mirror the closest existing repository/configuration as the reference example.
Before finishing
Run dotnet build on the affected projects and dotnet test on the Infrastructure test
project. Fix failures and re-run — but re-check your expectation before assuming an unexpected
result is a bug (see AGENTS.md's "iterate without tunnel vision"; e.g. a migration diff that
comes back empty because the model genuinely didn't change is correct, not broken). End your
response with a one-line footer: Chat mode used: Infrastructure Layer.