coreex-policy

Creates CoreEx Application-layer policy classes encapsulating async guard logic with Result<T> pipelines.

28|8|Updated Feb 21, 2022
One-click install
npx skills add https://github.com/Avanade/CoreEx --skill coreex-policy-avanade
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: coreex-policy
Source: https://github.com/Avanade/CoreEx/tree/main/.github/skills/coreex-policy
Command: npx skills add https://github.com/Avanade/CoreEx --skill coreex-policy-avanade

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Domain guard checks that require async I/O — such as verifying a referenced entity exists via an adapter or repository — cannot live in synchronous validators or directly in domain aggregates. This Skill scaffolds a named, independently testable CoreEx policy class in Application/Policies/ that encapsulates those guards and composes cleanly into Result<T> pipelines. ## Core Features & Use Cases - EnsureExists Guards: Fetch an entity through an adapter and translate NotFoundError into a field-level ValidationError (HTTP 400) or a NotFoundException with WithErrorCode/WithKey (HTTP 404), depending on whether the id is a body property or path parameter. - Business Rule Guards: Implement state/condition checks (e.g. EnsureActiveAsync) returning Result.BusinessError with machine-readable error codes. - Localizable Messages: Use LText static fields for entity names inside error messages while keeping property names as plain strings via MessageItem.CreateErrorMessage. - Unit Test Generation: Produce matching {Name}PolicyTests.cs with Moq-based adapter mocks covering success, validation-error, and business-error paths. - Use Case: When building an order service that must verify a product exists and is active before adding it to a basket, generate a ProductPolicy with EnsureExistsAsync and EnsureActiveAsync, then compose it into the service's Result.GoAsync().ThenAsAsync() pipeline. ## Quick Start Ask the AI to create a CoreEx policy class that ensures a referenced entity exists via its adapter, returning the loaded entity as Result<T> with a matching unit test class.

Frequently Asked Questions about coreex-policy

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a CoreEx policy class for entity existence checks?▼

Create a class in Application/Policies/ that accepts the adapter via its constructor, then implement EnsureExistsAsync using Result.GoAsync with an OnFailure handler that translates IsNotFoundError into Result.ValidationError. Instantiate it at the call site rather than registering it in DI.

When should I use a policy instead of a validator in CoreEx?▼

Use a policy when the guard requires async I/O, such as calling an adapter or repository to load state. Synchronous field validation without I/O belongs in a validator, while guards that fit entirely inside the domain aggregate should stay in the aggregate method.

Should a CoreEx policy return ValidationError or NotFoundException?▼

Return ValidationError (HTTP 400) when the id is a request-body property so the error links to the field. Return a NotFoundException with WithErrorCode and WithKey (HTTP 404) when the id is a path or query parameter identifying the primary resource.

Can CoreEx policies be registered in dependency injection?▼

No, policies are never registered in DI. They are instantiated at the call site with new, receiving adapters or repositories already injected into the calling service as constructor arguments.

How do I unit test a CoreEx policy class?▼

Create a {Name}PolicyTests class deriving from WithGenericTester<EntryPoint>, mock the adapter interface with Moq, and wrap each test in Test.Scoped. Assert IsSuccess for passing guards, IsValidationError for not-found guards, and IsBusinessError for state violations.

What is the difference between BusinessError and ValidationError in CoreEx?▼

ValidationError signals a constraint violation tied to a specific input field, such as a referenced entity not found. BusinessError signals a domain or process rule violation, such as an entity being inactive, and supports machine-readable error codes via WithErrorCode.