add-concept
Use this skill when asked to create a strongly-typed domain identifier or value (such as ProjectId, AuthorName, InvoiceNumber) in a Cratis-based project. Produces a ConceptAs<T> record with the correct conversions and sentinel values.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Create a strongly-typed Concept that wraps a primitive domain value.
Never use raw primitives in domain models
Replace Guid, string, int, etc. with a ConceptAs<T> record whenever the value has domain meaning.
Template
// Copyright (c) Cratis. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Cratis.Concepts;
namespace <NamespaceRoot>.<Feature>;
/// <summary>
/// Represents the identity of a <description>.
/// </summary>
/// <param name="Value">The underlying <type> value.</param>
public record <ConceptName>(<UnderlyingType> Value) : ConceptAs<<UnderlyingType>>(Value)
{
/// <summary>
/// Represents an unset <ConceptName>.
/// </summary>
public static readonly <ConceptName> NotSet = new(<emptyValue>);
/// <summary>
/// Implicitly converts a <UnderlyingType> to a <ConceptName>.
/// </summary>
public static implicit operator <ConceptName>(<UnderlyingType> value) => new(value);
}
Add when backed by Guid
/// <summary>
/// Creates a new <ConceptName> with a unique value.
/// </summary>
/// <returns>A new <ConceptName>.</returns>
public static <ConceptName> New() => new(Guid.NewGuid());
Add when used as an event-source ID
/// <summary>
/// Implicitly converts a <ConceptName> to an <see cref="EventSourceId"/>.
/// </summary>
/// <param name="id">The <ConceptName> to convert.</param>
public static implicit operator EventSourceId(<ConceptName> id) => new(id.Value.ToString());
Empty/sentinel values
| Underlying type | Use |
|---|---|
Guid |
Guid.Empty |
string |
string.Empty |
int |
0 |
long |
0L |
Placement rules
- Do NOT create a
Concepts/folder - Place the file in the folder that semantically owns the concept
-
ProjectId→Features/Projects/ - Shared cross-feature concepts → project source root
-
Checklist
- Inherits
ConceptAs<T> - Has a
static readonly NotSet(orEmpty) sentinel - Has implicit conversion from the primitive
- Has implicit conversion to
EventSourceIdif used as event-source key - Has
New()factory ifGuid-backed - Copyright header present
-
dotnet buildpasses
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-03-11
- 索引更新时间
- 2026-03-11
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!