Class NamedEntity<T>
Provides an abstract base class for domain entities that require human-readable identification. This class extends BaseEntity<T> by adding name and description properties for entities that need to be presented or referenced by name in user interfaces and business operations.
[ExcludeFromCodeCoverage]
public abstract class NamedEntity<T> : BaseEntity<T>, IAuditable
Type Parameters
- Inheritance
-
BaseEntity<T>NamedEntity<T>
- Implements
- Derived
- Inherited Members
Examples
// Example implementation for a product category
public class Category : NamedEntity<Guid>
{
public override required Guid id { get; init; } = Guid.NewGuid();
// Name and Description are inherited and can be used directly
public Category(string name, string description = "")
{
Name = name;
Description = description;
}
}
// Usage example
var category = new Category("Electronics", "Consumer electronics and gadgets")
{
CreatedBy = userId,
IsImportant = true
};
// The entity provides both technical and business identification
Console.WriteLine($"Category ID: {category.id}");
Console.WriteLine($"Category Name: {category.Name}");
Console.WriteLine($"Description: {category.Description}");
Remarks
NamedEntity is designed for domain entities that require human-readable identification beyond their technical identifiers. It provides a standardized structure for entities that are commonly referenced by name in business operations, user interfaces, and reporting.
The class establishes a consistent property order for JSON serialization:
1. id - The unique technical identifier (inherited from BaseEntity<T>)
2. Name - The human-readable name for display and reference purposes
3. Description - Optional detailed description for additional context
4. Audit properties - Creation, modification, and metadata fields (inherited)
Common Use Cases: - Catalog entities (products, categories, brands) - Configuration entities (settings, templates, rules) - Reference data (countries, currencies, status codes) - User-manageable entities (projects, organizations, groups)
Design Considerations: - Name property is mutable to support business requirements for renaming - Description is optional and can be empty for simple entities - Inherits full audit trail capabilities from BaseEntity - Supports soft deletion and importance marking
Properties
Description
Gets or sets an optional detailed description of the entity. This property provides additional context and information beyond the basic name.
[JsonPropertyOrder(2)]
public string Description { get; set; }
Property Value
- string
A string containing a detailed description of the entity. Defaults to an empty string. Can be used for documentation, help text, or extended information display.
Remarks
The Description property enhances entity understanding and usability: - Provides detailed explanation or context for the entity - Supports user guidance in interfaces through help text or tooltips - Enables rich content for catalogs, documentation, and reports - Facilitates full-text search scenarios beyond just name matching
Content Guidelines: - Should provide value beyond what the name already conveys - Can include usage instructions, specifications, or business context - Consider markdown or structured text for rich formatting needs - Keep length appropriate for intended display contexts
Optional Nature: - Can be empty for simple entities where name is self-explanatory - Length and content vary based on entity complexity and business needs - Consider character limits based on storage and display requirements - May support internationalization for multi-language deployments
Name
Gets or sets the human-readable name of the entity. This property provides a business-friendly identifier for display, searching, and reference purposes.
[JsonPropertyOrder(1)]
public string Name { get; set; }
Property Value
- string
A string representing the entity's name. Defaults to an empty string for new entities. The name should be meaningful to business users and suitable for display in user interfaces.
Remarks
The Name property serves multiple purposes in the domain model: - Primary display text in user interfaces and reports - Search and filtering criteria for entity lookup - Business reference in logs, audit trails, and documentation - Human-readable identifier in API responses and exports
Naming Guidelines: - Should be concise but descriptive enough for clear identification - Consider internationalization requirements for multi-language support - Avoid technical jargon unless the audience consists of technical users - Ensure uniqueness where business rules require it (enforced at the business logic level)
Implementation Notes: - Ordered as the second property in JSON serialization (after id) - Mutable to support business scenarios requiring entity renaming - No built-in validation - validation should be implemented in domain services - Consider implementing change tracking if name history is important