MasLazu.AspNet.ApiKey.Domain
1.0.0-preview.1
dotnet add package MasLazu.AspNet.ApiKey.Domain --version 1.0.0-preview.1
NuGet\Install-Package MasLazu.AspNet.ApiKey.Domain -Version 1.0.0-preview.1
<PackageReference Include="MasLazu.AspNet.ApiKey.Domain" Version="1.0.0-preview.1" />
<PackageVersion Include="MasLazu.AspNet.ApiKey.Domain" Version="1.0.0-preview.1" />
<PackageReference Include="MasLazu.AspNet.ApiKey.Domain" />
paket add MasLazu.AspNet.ApiKey.Domain --version 1.0.0-preview.1
#r "nuget: MasLazu.AspNet.ApiKey.Domain, 1.0.0-preview.1"
#:package MasLazu.AspNet.ApiKey.Domain@1.0.0-preview.1
#addin nuget:?package=MasLazu.AspNet.ApiKey.Domain&version=1.0.0-preview.1&prerelease
#tool nuget:?package=MasLazu.AspNet.ApiKey.Domain&version=1.0.0-preview.1&prerelease
MasLazu.AspNet.ApiKey.Domain
Domain layer containing the core business entities for API key management.
Overview
This project defines the domain entities that represent the core business concepts of API key management. It contains the fundamental building blocks that model the business domain.
Domain Entities
ApiKey
Represents an API key entity with all its properties and relationships:
public class ApiKey : BaseEntity
{
public Guid UserId { get; set; }
public string Key { get; set; } = string.Empty;
public string? Name { get; set; }
public DateTime? ExpiresDate { get; set; }
public DateTime? LastUsed { get; set; }
public DateTime? RevokedDate { get; set; }
public ICollection<ApiKeyScope> Scopes { get; set; } = [];
}
Properties:
UserId: The user who owns this API keyKey: The actual API key value (string)Name: Optional human-readable name for the keyExpiresDate: Optional expiration dateLastUsed: Timestamp of last usageRevokedDate: Timestamp when key was revokedScopes: Navigation property to related permission scopes
ApiKeyScope
Represents a permission scope associated with an API key:
public class ApiKeyScope : BaseEntity
{
public Guid ApiKeyId { get; set; }
public Guid PermissionId { get; set; }
public ApiKey? ApiKey { get; set; }
}
Properties:
ApiKeyId: Reference to the parent API keyPermissionId: Reference to the permission this scope grantsApiKey: Navigation property back to the API key
Dependencies
- .NET 9.0
- MasLazu.AspNet.Framework.Domain (1.0.0-preview.6)
Dependencies Diagram
graph TD
A[MasLazu.AspNet.ApiKey.Domain] --> B[MasLazu.AspNet.Framework.Domain]
Base Entity
Both entities inherit from BaseEntity which provides:
Id: Unique identifier (Guid)CreatedAt: Creation timestampUpdatedAt: Last update timestamp
Relationships
ApiKey (1) ──── (Many) ApiKeyScope
│ │
└─ UserId └─ PermissionId
- One-to-Many: One API key can have multiple permission scopes
- Many-to-One: Multiple scopes can reference the same permission
Business Rules
ApiKey Rules
- Each API key belongs to exactly one user
- API key values must be unique
- Keys can have optional expiration dates
- Revoked keys cannot be used for authentication
- Keys track their last usage for monitoring
ApiKeyScope Rules
- Each scope links one API key to one permission
- Scopes are used for fine-grained access control
- Multiple scopes can reference the same permission
- Scopes inherit the lifecycle of their parent API key
Usage
Domain entities are used by:
- Repository Layer: For data persistence operations
- Service Layer: For business logic implementation
- Mapping Layer: For converting to/from DTOs
Project Structure
MasLazu.AspNet.ApiKey.Domain/
├── Entities/
│ ├── ApiKey.cs
│ └── ApiKeyScope.cs
└── MasLazu.AspNet.ApiKey.Domain.csproj
Design Principles
- Rich Domain Model: Entities contain business logic and validation
- Entity Relationships: Proper navigation properties for data access
- Type Safety: Strong typing with nullable reference types
- Clean Architecture: Domain entities are independent of infrastructure concerns
- Business Focus: Entities model real business concepts, not database tables
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 was computed. 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. |
-
net9.0
- MasLazu.AspNet.Framework.Domain (>= 1.0.0-preview.6)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on MasLazu.AspNet.ApiKey.Domain:
| Package | Downloads |
|---|---|
|
MasLazu.AspNet.ApiKey.EfCore
EF Core implementation for MasLazu ASP.NET API Key management. Contains data access layer using Entity Framework Core. |
|
|
MasLazu.AspNet.ApiKey
Core service layer for MasLazu ASP.NET API Key management. Contains service implementations for API key operations. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-preview.1 | 224 | 9/20/2025 |
See RELEASES.md for release notes.