Skip to content
Back to skills

Coreex Adapter

ASecurity

Create or modify a CoreEx Infrastructure-layer adapter (anti-corruption layer). USE FOR: new adapter interface in Application/Adapters/{ExternalDomain}/, new adapter implementation in Infrastructure/Adapters/{ExternalDomain}/, new typed HTTP client in Infrastructure/Clients/{ExternalDomain}/, event-driven sync/replication adapter (IXxxSyncAdapter), unit tests for HTTP clients with MockHttpClientFactory. DO NOT USE FOR: repositories within the same domain (use coreex-repository), application s...

  • 29 stars
  • 0 votes
  • 0 copies
  • 7 views
  • Added August 31, 2026
databasessqlnodetestinggitapi

Works with

  • terminal
  • cli
  • api

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned November 29, 2026

npx -y skills add Avanade/CoreEx --skill coreex-adapter --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Coreex Adapter?

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

Security grade badge for Coreex Adapter
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/avanade-coreex-adapter/badge)](https://www.skillsdirectory.com/skills/avanade-coreex-adapter)

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: coreex-adapter
description: "Create or modify a CoreEx Infrastructure-layer adapter (anti-corruption layer). USE FOR: new adapter interface in Application/Adapters/{ExternalDomain}/, new adapter implementation in Infrastructure/Adapters/{ExternalDomain}/, new typed HTTP client in Infrastructure/Clients/{ExternalDomain}/, event-driven sync/replication adapter (IXxxSyncAdapter), unit tests for HTTP clients with MockHttpClientFactory. DO NOT USE FOR: repositories within the same domain (use coreex-repository), application services that call adapters (use coreex-app-service), event subscriber hosts that drive sync adapters (see coreex-event-subscribers.instructions.md)."
argument-hint: "Optional: external domain name, operations needed (get/reserve/cancel/sync), synchronous vs replication role, HTTP or local-store-only"
tags: ["adapter", "anti-corruption", "http-client", "infrastructure", "integration", "coreex"]
---

<!--
  AI workflow asset — dual-audience notice:
  - In the Avanade/CoreEx repository: this file is the authored source. Edit it here.
  - In a consumer repository: this file was generated by `dotnet new coreex-ai` (or refreshed via
    `dotnet new coreex-ai --force` / the `/coreex-docs-sync` skill). Do not hand-edit it directly —
    propose the change upstream in Avanade/CoreEx instead, then refresh once it is released.
-->

# CoreEx: Adapter (Anti-Corruption Layer)

Guides you through adding or modifying an adapter — the boundary that isolates your domain from an external system. Covers the Application-layer interface, Infrastructure-layer implementation, typed HTTP client, sub-folder conventions, registration, and unit testing.

## When to Use

- Add an `IXxxAdapter` interface for a new external-domain dependency
- Add a synchronous real-time adapter (HTTP call + optional local store read/event publish)
- Add a replication adapter (`IXxxSyncAdapter`) for event-driven data sync into your local store
- Add or extend a typed HTTP client (`XxxHttpClient`) in `Infrastructure/Clients/{ExternalDomain}/`
- Validate consumed response fields inside a typed HTTP client using `WithValidator`
- Unit-test HTTP client response-code handling with `MockHttpClientFactory`

## When Not to Use

- Sending a command end-to-end (call site, queue topology, tests, Aspire) — use `coreex-command-publish-e2e`, which invokes this skill for the adapter step
- EF repositories within the same domain — use `coreex-repository`
- Application services that consume the adapter — use `coreex-app-service`
- Event subscriber hosts that drive `IXxxSyncAdapter` — use `coreex-subscriber`

> **Resolve project-wide choices from state before asking.** Read the solution-root `AGENTS.md`
> **Feature Configuration** for `messaging-provider` (does this domain publish/consume events?) and `data-provider` (`SqlServer` / `Postgres` / `Cosmos` / `None`)
> (provider-specific local-store replication vs HTTP). Only prompt for what is unresolved; include resolved values in the implementation plan.

## Quick Reference

- **Always use a sub-folder** per external domain: `Application/Adapters/{ExternalDomain}/`, `Infrastructure/Adapters/{ExternalDomain}/`, `Infrastructure/Clients/{ExternalDomain}/`
- Interface surface must be **domain-idiomatic** — never a mirror of the remote API's shape
- Messaging adapters use the configured `IEventPublisher` backed by `ServiceBusPublisher` or outbox, not `ServiceBusSender` plus manual formatting. Direct means bypassing the outbox, not CoreEx. Preserve custom implementations/decorators and supported overrides; raw SDK sending needs a concrete documented requirement. Without an outbox, add and await `PublishAsync(cancellationToken)` in the operation's scope.
- Adapter methods model expected success and business outcomes with `Result` or `Result<T>`; transport, cancellation, deserialization, and unexpected validation exceptions can still escape
- `[ScopedService<IXxxAdapter>]` on the implementation — auto-discovered via `AddDynamicServicesUsing<T>()`
- Typed HTTP client registered via `builder.AddTypedHttpClient<XxxHttpClient>("ServiceName")` in `Program.cs` — auto-configures `BaseAddress`, `IdempotencyKeyHandler`, service discovery, and standard resilience handlers
- **Do not treat retries as idempotency.** Never enable retries for provisioning or other mutating operations unless the remote contract guarantees idempotency (for example, a stable idempotency key); when delivery may be repeated after an unknown outcome, reconcile through a lookup before creating again
- Never call `HttpClient` directly in adapter methods — always delegate to the typed client class
- Inside the client, use `client.Send(method, uri)` or `Get`/`Post`/`Put`/`Patch`/`Delete`, then `WithJson(value)` for JSON or `WithContent(content)` for explicit content. The builder is single-use, exactly one body assignment is allowed, and `Patch` does not imply JSON Merge Patch. Configure headers, queries, and paging before terminal execution.
- **Response validation belongs to the client**, not `Application/Validators/`. For small, client-only rules use a private static readonly `Validator<T>` configured once with `Validator.Create<T>().HasProperty(...)`, then chain `.WithValidator(_validator).ToResultAsync(ct)`. Validate fields the consumer requires; do not copy create/update rules or add identifier matching by default. Extract a colocated validator only when complexity or genuine reuse warrants it; see the workflow.
- Do not use `System.Text.Json`'s `[JsonRequired]` on adapter or HTTP-client wire DTOs to enforce required fields; it fails during deserialization before CoreEx validation can report the problem. Validate required response fields in the typed client, and outbound payloads before sending when their contract requires it.
- Terminal methods on `HttpRequestBuilder` (`ToResultAsync`, `GetValueAsync<T>`, etc.) **automatically dispose** the response. When inspecting raw responses (e.g. `builder.GetResponseAsync()`), dispose the response with `using var`. Reported validation errors become `HttpRequestException` failures with inner diagnostics, not caller validation errors. Test inline rules through the client, including invalid 2xx responses and success; cached adapters must not cache invalid responses.
- `response.ToResultAsync()` maps HTTP status to `Result` (2xx → `Success`, error + ProblemDetails → `BusinessException`/`ProblemDetailsException`, plain error → `HttpRequestException`); transport and cancellation exceptions may still propagate
- `response.ToResultAsync<T>()` is for responses that **must** carry a value — a null/empty body (including 204) is an `HttpRequestException` failure, so the result is `Result<T>` with a non-null `T` and callers need no null handling. Use `ToResultOrDefaultAsync<T>()` (→ `Result<T?>`) only where a missing body is genuinely valid; `GetValueAsync<T>()`/`GetValueOrDefaultAsync<T>()` are the throwing equivalents. Map specific status codes fluently using `.WithStatusResult(HttpStatusCode.NotFound, () => Result.NotFoundError())` (which short-circuits validation and deserialization) when "not found" is an expected outcome
- Map 404 to entity-not-found only when that is the downstream endpoint's expected contract; route/deployment/configuration failures are not invalid caller references. The application service/policy decides missing target (404) versus missing body reference (field-level 400) and preserves other failures; see [Not Found Handling](/.github/instructions/coreex-application-services.instructions.md#not-found-handling).
- **Real-time read adapters should cache successes** with `IHybridCache.GetOrCreateWithResultAsync<T>(key, factory, options, ct)` — the adapter method becomes one line; only successful results are cached (failures such as not-found are never cached). Use short expiry via `HybridCacheEntryOptions.CreateFor<T>(...)` (overridable through `CoreEx:Caching:{Type}:*`). Concurrent cache misses are collapsed to one factory call per key per node with `FusionHybridCache` (cross-node needs an opt-in FusionCache distributed locker; non-FusionCache implementations such as `MemoryOnlyHybridCache` don't collapse them) — keep the factory an idempotent read. Tests must then clear the cache per test and register a hybrid cache in the unit-test host (see `references/workflow.md` → "Caching a real-time adapter")
- Two distinct adapter roles in the samples — **synchronous** (real-time HTTP + events) and **replication** (event-driven local-store write; EF in relational domains, `CosmosDb` containers in Cosmos domains); separate interfaces, separate implementations
- **Generate `*.Test.Unit/Clients/{ExternalDomain}/{External}HttpClientTests.cs`** for a typed HTTP client used by a synchronous or replication adapter — cover success (2xx), server error (5xx), and business error (422/ProblemDetails) per endpoint; skip for store-only replication adapters (no HTTP) and for combined local-store+HTTP+events orchestration adapters (mock the client via `Test.ReplaceHttpClientFactory` in integration tests instead)

For full workflow and code examples see [`references/workflow.md`](references/workflow.md).

## Key References

- [`/.github/instructions/coreex-repositories.instructions.md`](/.github/instructions/coreex-repositories.instructions.md) — Infrastructure conventions (adapters, clients, mapping)
- [`/.github/instructions/coreex-application-services.instructions.md`](/.github/instructions/coreex-application-services.instructions.md) — Application conventions (adapter interfaces, anti-corruption layer)
- Related skills: [`coreex-repository`](../coreex-repository/SKILL.md) (same-domain persistence), [`coreex-app-service`](../coreex-app-service/SKILL.md) (consumes the adapter), [`coreex-subscriber`](../coreex-subscriber/SKILL.md) (drives `IXxxSyncAdapter`)
- [Infrastructure layer deep-dive](/.github/docs/coreex/infrastructure-layer.md) — optional (after `/coreex-docs-sync`)
- Illustrative examples (CoreEx sample — not present in your project):
  - [synchronous + replication adapter interfaces](https://github.com/Avanade/CoreEx/tree/main/samples/src/Contoso.Shopping.Application/Adapters/Products) — `IProductAdapter`, `IProductSyncAdapter`
  - [adapter + client implementations](https://github.com/Avanade/CoreEx/tree/main/samples/src/Contoso.Shopping.Infrastructure/Adapters/Products) and the [typed HTTP client](https://github.com/Avanade/CoreEx/tree/main/samples/src/Contoso.Shopping.Infrastructure/Clients/Products)
  - [real-time cached adapter](https://github.com/Avanade/CoreEx/tree/main/samples/src/Contoso.Shopping.Infrastructure/Adapters/Customers) (`ICustomerAdapter`) and its [value-returning client](https://github.com/Avanade/CoreEx/tree/main/samples/src/Contoso.Shopping.Infrastructure/Clients/Customers) — the alternate, no-replication pattern

Files in this skill

  • SKILL.md5.5 KB
  • references/workflow.md16.2 KB

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 databases →

Comments

Loading comments…

Newsletter

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