structid

Generate strongly-typed struct-based IDs with serialization and database support.

41|1|Updated Nov 19, 2024
One-click install
npx skills add https://github.com/devlooped/StructId --skill structid
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: structid
Source: https://github.com/devlooped/StructId/tree/main/src
Command: npx skills add https://github.com/devlooped/StructId --skill structid

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

StructId helps you avoid “stringly-typed” and loosely-typed identifier bugs by making every ID a distinct, strongly-typed value (as a readonly partial record struct), while keeping runtime dependencies at zero through source generation.

Core Features & Use Cases

  • Strongly-typed identifiers: Define IStructId (string-backed) and IStructId<TValue> (struct-backed) IDs using readonly partial record struct so your compiler prevents mixing IDs accidentally.
  • Factories via INewable: Use INewable<TSelf> / INewable<TSelf, TValue> for consistent New(...) creation patterns (including parameterless New() for Guid and Ulid-backed IDs).
  • Integration that “just activates”: Enable EF Core converters, Dapper type handlers, and System.Text.Json / Newtonsoft.Json converters automatically when you reference the corresponding packages.
  • Template-based extension: Extend multiple (or filtered) ID types using [TStructId] templates and specialized per-value-type handlers using [TValue].

Quick Start

Ask the AI: “Given I want a typed UserId(Guid) and a typed ProductId(int), show the two readonly partial record struct declarations using StructId and explain which New(...) overloads to call and how to enable EF Core and Dapper support.”

Frequently Asked Questions about structid

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

FAQPage Schema
How do I create strongly-typed identifiers in C# to prevent ID mix-ups?

Strongly-typed identifiers prevent ID mix-ups by generating readonly partial record struct types that implement IStructId, ensuring the compiler catches accidental cross-assignment of different ID types at compile time.

What is the best way to generate typed IDs without adding runtime dependencies?

Generating typed IDs without runtime dependencies is achieved via C# source generators, which emit the required readonly record struct code at compile time, keeping your deployed assembly footprint completely clean.

How do I enable EF Core and Dapper serialization for strongly-typed struct IDs?

EF Core and Dapper serialization for strongly-typed struct IDs is enabled automatically by referencing the corresponding packages, which triggers the source generator to output the necessary converters and type handlers.

Can I use System.Text.Json or Newtonsoft.Json with strongly-typed record struct IDs?

System.Text.Json and Newtonsoft.Json are fully supported with strongly-typed record struct IDs, as the source generator automatically creates the required JSON converters when it detects those referenced dependencies.

How do I implement a consistent New() factory method for Guid and Ulid-backed typed IDs?

A consistent New() factory method for Guid and Ulid-backed typed IDs is implemented by applying the INewable<TSelf> or INewable<TSelf, TValue> interfaces to your readonly partial record struct declarations.

How do I apply custom templates across multiple strongly-typed struct identifiers?

Custom templates are applied across multiple strongly-typed struct identifiers using the [TStructId] attribute for broad ID types and the [TValue] attribute for specialized per-value-type handlers.