MasLazu.AspNet.Verification.Abstraction
1.0.0-preview.6
dotnet add package MasLazu.AspNet.Verification.Abstraction --version 1.0.0-preview.6
NuGet\Install-Package MasLazu.AspNet.Verification.Abstraction -Version 1.0.0-preview.6
<PackageReference Include="MasLazu.AspNet.Verification.Abstraction" Version="1.0.0-preview.6" />
<PackageVersion Include="MasLazu.AspNet.Verification.Abstraction" Version="1.0.0-preview.6" />
<PackageReference Include="MasLazu.AspNet.Verification.Abstraction" />
paket add MasLazu.AspNet.Verification.Abstraction --version 1.0.0-preview.6
#r "nuget: MasLazu.AspNet.Verification.Abstraction, 1.0.0-preview.6"
#:package MasLazu.AspNet.Verification.Abstraction@1.0.0-preview.6
#addin nuget:?package=MasLazu.AspNet.Verification.Abstraction&version=1.0.0-preview.6&prerelease
#tool nuget:?package=MasLazu.AspNet.Verification.Abstraction&version=1.0.0-preview.6&prerelease
MasLazu.AspNet.Verification.Abstraction
The Abstraction layer of the MasLazu ASP.NET Verification system. This project defines the core contracts, data models, and domain types that form the foundation of the verification system.
๐ Overview
This is the abstraction layer that defines the public API and data contracts for the verification system. It contains interfaces, data transfer objects (DTOs), enums, and events that other layers implement and use.
๐๏ธ Architecture
This project represents the Abstraction Layer in Clean Architecture:
- Interfaces: Service contracts and abstractions
- Models: Data transfer objects and request/response models
- Enums: Domain enumerations and constants
- Events: Domain events for inter-system communication
๐ฆ Dependencies
Package References
MasLazu.AspNet.Framework.Application- Base framework with common abstractions
๐ Core Components
Service Interfaces
IVerificationService
The main interface for verification operations:
public interface IVerificationService
{
Task<VerificationDto?> GetByCodeAsync(Guid userId, string code, CancellationToken ct = default);
Task<bool> IsCodeValidAsync(Guid userId, string code, CancellationToken ct = default);
Task<VerificationDto> VerifyAsync(string code, CancellationToken ct = default);
Task<VerificationDto> CreateVerificationAsync(Guid userId, CreateVerificationRequest request, CancellationToken ct = default);
Task<VerificationDto> SendVerificationAsync(Guid userId, SendVerificationRequest request, CancellationToken ct = default);
}
IVerificationPurposeService
Interface for managing verification purposes:
public interface IVerificationPurposeService
{
Task<VerificationPurposeDto> CreateIfNotExistsAsync(Guid id, CreateVerificationPurposeRequest createRequest, CancellationToken ct = default);
}
Data Models
VerificationDto
Core data transfer object for verification information:
public record VerificationDto(
Guid Id,
Guid UserId,
VerificationChannel Channel,
string Destination,
string VerificationCode,
string VerificationPurposeCode,
VerificationStatus Status,
int AttemptCount,
DateTimeOffset ExpiresAt,
DateTimeOffset? VerifiedAt,
VerificationPurposeDto? VerificationPurpose,
DateTimeOffset CreatedAt,
DateTimeOffset? UpdatedAt
) : BaseDto(Id, CreatedAt, UpdatedAt);
Request Models
CreateVerificationRequest
public record CreateVerificationRequest(
Guid UserId,
VerificationChannel Channel,
string Destination,
string VerificationPurposeCode,
DateTimeOffset? ExpiresAt = null
);
SendVerificationRequest
public record SendVerificationRequest(
Guid UserId,
string Destination,
string PurposeCode,
DateTimeOffset? ExpiresAt = null
);
UpdateVerificationRequest
public record UpdateVerificationRequest(
Guid Id,
Guid UserId,
VerificationChannel? Channel,
string? Destination,
string? VerificationPurposeCode,
VerificationStatus? Status,
DateTimeOffset? ExpiresAt,
DateTimeOffset? UpdatedAt
);
VerificationPurposeDto
Data transfer object for verification purposes:
public record VerificationPurposeDto(
Guid Id,
string Code,
string Name,
string? Description,
bool IsActive,
DateTimeOffset CreatedAt,
DateTimeOffset? UpdatedAt
) : BaseDto(Id, CreatedAt, UpdatedAt);
Domain Enums
VerificationChannel
Defines the communication channels for verification:
public enum VerificationChannel
{
Email
}
Extensibility Note: Currently supports Email, but can be extended to include SMS, Push notifications, etc.
VerificationStatus
Represents the lifecycle states of a verification:
public enum VerificationStatus
{
Pending, // Code created, awaiting verification
Verified, // Code successfully verified
Failed // Verification failed or expired
}
Domain Events
VerificationCompletedEvent
Event published when verification is completed:
public class VerificationCompletedEvent
{
public Guid VerificationId { get; set; }
public Guid UserId { get; set; }
public string Email { get; set; } = string.Empty;
public string PurposeCode { get; set; } = string.Empty;
public DateTime CompletedAt { get; set; }
public bool IsSuccessful { get; set; }
}
๐ง Usage Examples
Implementing IVerificationService
public class VerificationService : IVerificationService
{
public async Task<VerificationDto> CreateVerificationAsync(Guid userId, CreateVerificationRequest request, CancellationToken ct = default)
{
// Implementation logic
var verification = new VerificationDto(
Id: Guid.NewGuid(),
UserId: userId,
Channel: request.Channel,
Destination: request.Destination,
VerificationCode: GenerateCode(),
VerificationPurposeCode: request.VerificationPurposeCode,
Status: VerificationStatus.Pending,
AttemptCount: 0,
ExpiresAt: request.ExpiresAt ?? DateTimeOffset.UtcNow.AddMinutes(15),
VerifiedAt: null,
VerificationPurpose: null,
CreatedAt: DateTimeOffset.UtcNow,
UpdatedAt: null
);
return verification;
}
// Other interface implementations...
}
Using Request Models
// Creating a verification
var createRequest = new CreateVerificationRequest(
UserId: Guid.NewGuid(),
Channel: VerificationChannel.Email,
Destination: "user@example.com",
VerificationPurposeCode: "registration",
ExpiresAt: DateTimeOffset.UtcNow.AddMinutes(15)
);
// Sending verification
var sendRequest = new SendVerificationRequest(
UserId: userId,
Destination: "user@example.com",
PurposeCode: "password-reset"
);
Handling Domain Events
// Publishing verification completed event
var verificationEvent = new VerificationCompletedEvent
{
VerificationId = verification.Id,
UserId = verification.UserId,
Email = verification.Destination,
PurposeCode = verification.VerificationPurposeCode,
CompletedAt = DateTime.UtcNow,
IsSuccessful = true
};
// Publish to message bus
await _publishEndpoint.Publish(verificationEvent);
๐ Design Principles
Clean Architecture Compliance
- No Implementation Details: Contains only abstractions and contracts
- Dependency Inversion: Higher-level modules depend on these abstractions
- Stable Interfaces: Changes to implementations don't affect consumers
Data Transfer Objects (DTOs)
- Immutability: Records ensure data integrity
- Inheritance: Extends
BaseDtofor common audit fields - Nullability: Proper nullable annotations for optional fields
Interface Segregation
- Focused Interfaces: Each interface has a single responsibility
- Async by Default: All operations are asynchronous with cancellation support
- Optional Parameters: Sensible defaults for common scenarios
๐ Event-Driven Design
The abstraction layer supports event-driven architecture through:
- Domain Events:
VerificationCompletedEventfor system integration - Message Contracts: Well-defined event structures
- Async Communication: Events can be published to message buses
๐ Extensibility
Adding New Channels
public enum VerificationChannel
{
Email,
Sms, // New channel
Push // Future channel
}
Extending Request Models
public record CreateVerificationRequest(
Guid UserId,
VerificationChannel Channel,
string Destination,
string VerificationPurposeCode,
DateTimeOffset? ExpiresAt = null,
string? CustomField = null // New optional field
);
Adding New Events
public class VerificationFailedEvent
{
public Guid VerificationId { get; set; }
public Guid UserId { get; set; }
public string Reason { get; set; } = string.Empty;
public DateTime FailedAt { get; set; }
}
๐งช Testing
Interface Testing
public class VerificationServiceTests
{
[Fact]
public async Task CreateVerificationAsync_ShouldReturnValidDto()
{
// Arrange
var mockService = new Mock<IVerificationService>();
var request = new CreateVerificationRequest(/* params */);
// Act
var result = await mockService.Object.CreateVerificationAsync(userId, request);
// Assert
Assert.NotNull(result);
Assert.Equal(VerificationStatus.Pending, result.Status);
}
}
Model Validation
[Fact]
public void VerificationDto_ShouldHaveRequiredFields()
{
var dto = new VerificationDto(/* params */);
Assert.NotEqual(Guid.Empty, dto.Id);
Assert.NotEqual(Guid.Empty, dto.UserId);
Assert.NotNull(dto.Destination);
}
๐ ๏ธ Development Guidelines
Naming Conventions
- Interfaces: Prefix with
I(e.g.,IVerificationService) - DTOs: Suffix with
Dto(e.g.,VerificationDto) - Requests: Suffix with
Request(e.g.,CreateVerificationRequest) - Events: Suffix with
Event(e.g.,VerificationCompletedEvent)
Code Structure
src/MasLazu.AspNet.Verification.Abstraction/
โโโ Enums/ # Domain enumerations
โโโ Events/ # Domain events
โโโ Interfaces/ # Service contracts
โโโ Models/ # DTOs and request models
โโโ MasLazu.AspNet.Verification.Abstraction.csproj
Best Practices
- Keep interfaces focused and minimal
- Use records for immutable DTOs
- Include XML documentation for public APIs
- Follow async/await patterns consistently
- Use meaningful property names and types
๐ค Contributing
- Interface Changes: Consider backward compatibility
- New Models: Follow existing naming and structure patterns
- Documentation: Update XML comments for new members
- Testing: Add tests for new abstractions
- Versioning: Consider semantic versioning for breaking changes
๐ License
Part of the MasLazu ASP.NET framework ecosystem.</content> <parameter name="filePath">/home/mfaziz/projects/cs/MasLazu.AspNet.Verification/src/MasLazu.AspNet.Verification.Abstraction/README.md
| 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.Application (>= 1.0.0-preview.15)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on MasLazu.AspNet.Verification.Abstraction:
| Package | Downloads |
|---|---|
|
MasLazu.AspNet.Authentication.Password
Application layer for MasLazu ASP.NET Password Authentication. Contains service implementations, validation, and business logic. |
|
|
MasLazu.AspNet.Authentication.Core.Base
Base implementations for MasLazu ASP.NET Authentication Core. Contains service implementations, JWT utilities, and application services. |
|
|
MasLazu.AspNet.Authentication.Core.Consumer
Event consumers for MasLazu ASP.NET Authentication Core. Contains MassTransit consumers for handling authentication-related events. |
|
|
MasLazu.AspNet.Verification.EfCore
Entity Framework Core implementation for ASP.NET verification system providing data access layer. |
|
|
MasLazu.AspNet.Verification.Endpoint
REST API endpoints for ASP.NET verification system using FastEndpoints. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-preview.6 | 161 | 10/2/2025 |
| 1.0.0-preview.5 | 169 | 10/1/2025 |
| 1.0.0-preview.4 | 155 | 9/29/2025 |
| 1.0.0-preview.3 | 169 | 9/29/2025 |
| 1.0.0-preview.2 | 138 | 9/28/2025 |
| 1.0.0-preview.1 | 302 | 9/18/2025 |