Class ResourceCollectionNameRegistry
Resolves the collection segment used when the framework synthesises a canonical
resource URI for ProblemDetails.Instance from a ResourceRef.
Override entries take precedence; otherwise the registry falls back to a naive plural
(type.ToLowerInvariant() + "s").
public sealed class ResourceCollectionNameRegistry
- Inheritance
-
ResourceCollectionNameRegistry
- Inherited Members
- Extension Methods
Remarks
Registered as a singleton via TryAddSingleton by AddTrellisAsp (which
leaves the registry empty by default), and pre-populated with the supplied overrides by
AddResourceCollectionName and AddResourceCollectionNames. Resource types
without an override fall back to the naive plural; calling AddTrellisAsp alone
means every type uses the naive plural. When none of those helpers are called, the
registry is absent from DI and Trellis.Asp.ResponseFailureWriter falls back to an
internal empty registry.
Override lookups are case-insensitive (OrdinalIgnoreCase)
so a domain that emits both ResourceRef.For<Person>() and
ResourceRef.For("person", id) sees the same plural.
Constructors
ResourceCollectionNameRegistry()
Creates an empty registry. Every lookup falls back to the naive plural.
public ResourceCollectionNameRegistry()
ResourceCollectionNameRegistry(IEnumerable<ResourceCollectionNameOverride>)
Creates a registry pre-populated from the supplied overrides. Used by DI when one or more ResourceCollectionNameOverride singletons have been registered.
public ResourceCollectionNameRegistry(IEnumerable<ResourceCollectionNameOverride> overrides)
Parameters
overridesIEnumerable<ResourceCollectionNameOverride>The override entries; may be empty.
Exceptions
- ArgumentNullException
Thrown when
overridesis null.- InvalidOperationException
Thrown when two overrides assign different collection names to the same resource type (matched case-insensitively). Identical overrides are coalesced silently so the same attribute discovered through overlapping assembly scans does not throw.
Methods
Resolve(string)
Resolves the collection segment for a given Type value.
Returns the registered override verbatim when one is present (case-insensitive
lookup, case-preserving result — an override registered as "People" emits
/People/{id}); otherwise returns the naive plural
resourceType.ToLowerInvariant() + "s". Callers wanting a lowercase guarantee
must lowercase the override at registration time.
public string Resolve(string resourceType)
Parameters
resourceTypestringThe resource type name as carried on ResourceRef.
Returns
- string
The collection segment to substitute into the synthesised URI.
Exceptions
- ArgumentException
Thrown when
resourceTypeis null or whitespace.