CoreEx.RefData
4.2.0
dotnet add package CoreEx.RefData --version 4.2.0
NuGet\Install-Package CoreEx.RefData -Version 4.2.0
<PackageReference Include="CoreEx.RefData" Version="4.2.0" />
<PackageVersion Include="CoreEx.RefData" Version="4.2.0" />
<PackageReference Include="CoreEx.RefData" />
paket add CoreEx.RefData --version 4.2.0
#r "nuget: CoreEx.RefData, 4.2.0"
#:package CoreEx.RefData@4.2.0
#addin nuget:?package=CoreEx.RefData&version=4.2.0
#tool nuget:?package=CoreEx.RefData&version=4.2.0
CoreEx.RefData
Provides the CoreEx reference data framework: typed base classes for reference data items and collections, a hybrid-cache-backed orchestrator, contextual date-validity checking, and a code-serialization collection.
Overview
CoreEx.RefData implements the domain concept of reference data — lookup tables (e.g. Status, Country, Currency) that are read frequently and change rarely. Items carry an Id, a Code, Text, Description, SortOrder, IsActive, and optional StartsOn/EndsOn date range, all of which participate in validity checking via ReferenceDataContext.
Two concrete base classes cover the most common identity types: ReferenceData<TSelf> (string Id) and ReferenceData<TId, TSelf> (arbitrary TId). Each exposes static TryGetById and TryGetByCode helpers that delegate to the ambient ReferenceDataOrchestrator registered in the DI container. Collections are thread-safe dictionaries keyed by both Id and Code; GetItems returns a stable, sorted IEnumerable by ReferenceDataSortOrder.
ReferenceDataHybridCache implements IReferenceDataCache on top of IHybridCache, using per-type semaphores to ensure that only one thread performs the expensive load while others wait, then everyone benefits from the cached result. ReferenceDataCodeCollection<TRef> solves the serialization problem: a property declared as a list of codes is stored as List<string?> on the wire but exposes ICollection<TRef> at the domain level.
Key capabilities
- 📚 Typed reference data base classes:
ReferenceData<TSelf>(string Id) andReferenceData<TId, TSelf>(typed Id) provideId,Code,Text,Description,SortOrder,IsActive,StartsOn/EndsOn, mapping support, andThrowIfInactive/ThrowIfInvalidguards. - 📋 Thread-safe collections:
ReferenceDataCollection<TRef>andReferenceDataCollection<TId, TRef>index items by bothIdandCode(case-insensitive by default) and exposeGetItems(sortOrder, activeOnly, isValid)for filtered, ordered enumeration. - 🔄 Hybrid-cache backing:
ReferenceDataHybridCacheimplementsIReferenceDataCacheviaIHybridCache; per-type semaphores prevent thundering-herd on cold start and support configurable entry options per item type viaOnCreateCacheEntry. - 📅 Contextual date validity:
ReferenceDataContextsupplies the reference date used to evaluateStartsOn/EndsOnon every item; the date can be set globally or overridden per type, defaulting toRuntime.UtcNow. - 🌐 Localised text and description:
TextandDescriptionare resolved throughLTexton every get, enabling locale-specific display strings without changing the domain model. - 🏷 Code-serialization collection:
ReferenceDataCodeCollection<TRef>stores codes asList<string?>for wire serialization while presenting anICollection<TRef>interface backed by the live orchestrator lookups. - 🔧 DI and health-check helpers:
AddReferenceDataOrchestratorand relatedIServiceCollectionextensions register the orchestrator, cache, andReferenceDataQuery.Default(enablingQueryAsync<TRef>()out of the box);ReferenceDataOrchestratorHealthCheckexposes a health-check endpoint reporting all registered reference data types. - 🔎 OData-esque query/paging:
ReferenceDataQuery(the defaultIReferenceDataQueryimplementation) filters, orders, and pages a reference data collection viaReferenceDataQueryArgsConfig— OData-esque$filteroncode/text(all string operators, case-insensitive) and$orderbyoncode/text/sortOrder. Supply aFunc<Type, QueryArgsConfig?>toReferenceDataQuery(configSelector)to use a different config per reference data type.
Reference-data code conversion
The Roslyn generator gives each concrete [ReferenceData] type an implicit conversion from string?:
BasketStatus? status = source.BasketStatusCode;
DiscountCoupon? coupon = source.DiscountCouponCode;
Pass code strings directly to concrete typed reference-data parameters and properties; no RefData<T> wrapper, code-only construction or conversion-only collection lookup is needed. Use an explicitly typed variable or cast when the expression does not provide a concrete target type; generic IReferenceData constraints do not expose concrete generated operators.
Conversion uses the current orchestrator. Null converts to null; unresolved non-null codes produce invalid instances retaining their codes, including when no current orchestrator exists. Requiredness, validity and activity must be checked separately. Use explicit collection lookups when querying the collection or requiring found/not-found semantics.
For a single reference-data field on a contract, declare [ReferenceData<T>] public partial string? XxxCode { get; set; } within a [Contract] partial class, not a plain code auto-property. Set XxxCode when mapping/arranging DTOs; use the generated typed Xxx accessor for reference-data behavior.
Key types
| Type | Description |
|---|---|
ReferenceData<TSelf> |
Abstract reference data base with string Id; provides static TryGetById/TryGetByCode, implicit/explicit string cast operators, and IComparable<TSelf> by code. |
ReferenceData<TId, TSelf> |
Abstract reference data base with arbitrary typed TId; same feature set as ReferenceData<TSelf> but with both Id and Code lookups. |
ReferenceDataCollection<TRef> |
Thread-safe IReferenceDataCollection with string Id; indexes by Id and Code, default sort by ReferenceDataSortOrder.SortOrder. |
ReferenceDataCollection<TId, TRef> |
Thread-safe IReferenceDataCollection with typed TId; otherwise identical to the string variant. |
ReferenceDataCodeCollection<TRef> |
Serializes a reference data relationship as a List<string?> of codes on the wire while presenting ICollection<TRef> at the domain level. |
ReferenceDataHybridCache |
IReferenceDataCache implementation backed by IHybridCache; per-type semaphores enforce single-loader semantics on cache miss; supports per-type entry-option customisation via OnCreateCacheEntry. |
ReferenceDataContext |
Supplies the contextual date used to evaluate StartsOn/EndsOn validity; settable globally or per reference data type. |
ReferenceDataSortOrder |
Enum: SortOrder, Id, Code, Text; controls the ordering returned by GetItems. |
ReferenceDataQuery |
Default IReferenceDataQuery implementation; auto-registered by AddReferenceDataOrchestrator. Accepts an optional per-type Func<Type, QueryArgsConfig?> selector via its constructor. |
ReferenceDataQueryArgsConfig |
QueryArgsConfig subclass pre-configured for reference data: $filter on code/text (all string operators, case-insensitive) and $orderby on code/text/sortOrder. Used by ReferenceDataQuery.Default. |
Namespaces
| Namespace | Description | Documentation |
|---|---|---|
CoreEx.RefData.Abstractions |
Core abstract implementations: ReferenceDataCore<TId> and ReferenceDataCollectionCore<TId, TRef> providing the full identity, validity, mapping, and collection infrastructure. |
📖 README |
CoreEx.RefData.HealthChecks |
ReferenceDataOrchestratorHealthCheck — reports all registered reference data types to the ASP.NET Core health-check endpoint. |
📖 README |
Related namespaces
CoreEx- DefinesIReferenceData,IReferenceDataCollection,IReferenceDataCache,ReferenceDataOrchestrator, andIHybridCacheconsumed throughout.CoreEx.Caching.FusionCache-FusionHybridCacheis the recommendedIHybridCacheimplementation for backingReferenceDataHybridCachein production.
AI Usage Guide
An AGENTS.md file is included with this package. AI coding assistants (GitHub Copilot, Claude, Cursor, etc.) that support workspace-injected package documentation will automatically surface concise usage guidance, code examples, and Do Not rules for this package without requiring a local CoreEx checkout.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- CoreEx (>= 4.2.0)
- CoreEx.Data (>= 4.2.0)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.13)
-
net8.0
- CoreEx (>= 4.2.0)
- CoreEx.Data (>= 4.2.0)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.32)
-
net9.0
- CoreEx (>= 4.2.0)
- CoreEx.Data (>= 4.2.0)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 9.0.21)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.2.0 | 77 | 10/24/2026 |
| 4.1.0 | 104 | 10/12/2026 |
| 4.0.0 | 124 | 9/21/2026 |
| 4.0.0-preview-5 | 123 | 8/23/2026 |
| 4.0.0-preview-4 | 113 | 8/21/2026 |
| 4.0.0-preview-3 | 153 | 8/4/2026 |
| 4.0.0-preview-2 | 119 | 7/10/2026 |
| 4.0.0-preview-1 | 136 | 6/20/2026 |