MasLazu.AspNet.ApiKey.Domain 1.0.0-preview.1

This is a prerelease version of MasLazu.AspNet.ApiKey.Domain.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MasLazu.AspNet.ApiKey.Domain" Version="1.0.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MasLazu.AspNet.ApiKey.Domain" Version="1.0.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="MasLazu.AspNet.ApiKey.Domain" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MasLazu.AspNet.ApiKey.Domain --version 1.0.0-preview.1
                    
#r "nuget: MasLazu.AspNet.ApiKey.Domain, 1.0.0-preview.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MasLazu.AspNet.ApiKey.Domain@1.0.0-preview.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MasLazu.AspNet.ApiKey.Domain&version=1.0.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=MasLazu.AspNet.ApiKey.Domain&version=1.0.0-preview.1&prerelease
                    
Install as a Cake Tool

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 key
  • Key: The actual API key value (string)
  • Name: Optional human-readable name for the key
  • ExpiresDate: Optional expiration date
  • LastUsed: Timestamp of last usage
  • RevokedDate: Timestamp when key was revoked
  • Scopes: 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 key
  • PermissionId: Reference to the permission this scope grants
  • ApiKey: 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 timestamp
  • UpdatedAt: 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.