Lewee.Common
0.40.3
dotnet add package Lewee.Common --version 0.40.3
NuGet\Install-Package Lewee.Common -Version 0.40.3
<PackageReference Include="Lewee.Common" Version="0.40.3" />
<PackageVersion Include="Lewee.Common" Version="0.40.3" />
<PackageReference Include="Lewee.Common" />
paket add Lewee.Common --version 0.40.3
#r "nuget: Lewee.Common, 0.40.3"
#:package Lewee.Common@0.40.3
#addin nuget:?package=Lewee.Common&version=0.40.3
#tool nuget:?package=Lewee.Common&version=0.40.3
Lewee.Common
This package provides shared utilities, constants, result types, and extension methods that are commonly used across Lewee applications and other Lewee packages.
Purpose
Lewee.Common contains cross-cutting concerns and common functionality that is used throughout the Lewee framework ecosystem. It provides:
- Result types for command and query responses
- Client message contracts for server-to-client communication
- Standardized constants for logging and HTTP headers
- Extension methods for common operations
Dependencies
FluentValidation- For validation failure handling in result types
Components
Authenticated User Service
IAuthenticatedUserService
Interface for accessing the current authenticated user's ID:
| Property | Type | Description |
|---|---|---|
UserId |
string? |
The user ID of the authenticated user, or null if not authenticated |
This interface is implemented by Lewee.Infrastructure.Auth for server-side ASP.NET Core applications (using IHttpContextAccessor) and can be implemented differently for client-side Blazor applications.
Result Types
Result (Abstract Base)
Base class for all result types with success/failure status and validation errors:
| Property | Type | Description |
|---|---|---|
IsSuccess |
bool |
Whether the request was successfully processed |
Status |
ResultStatus |
Enum indicating the type of result |
Errors |
IList<ValidationFailure> |
Validation errors keyed by property |
ResultStatus
Enum for categorizing result outcomes:
| Value | Description |
|---|---|
Success |
Request completed successfully |
ValidationError |
Input validation failed |
NotFound |
Requested resource not found |
DomainError |
Business rule violation |
UnexpectedError |
Unexpected system error |
NotApplicable |
Operation not applicable |
CommandResult
Result type for command operations (create, update, delete):
// Success
return CommandResult.Success();
// Failure with message
return CommandResult.Fail(ResultStatus.DomainError, "Order cannot be modified after completion");
// Failure with validation errors
return CommandResult.Fail(ResultStatus.ValidationError, validationFailures);
QueryResult<T>
Generic result type for query operations with data payload:
// Success with data
return QueryResult<OrderDto>.Success(orderDto);
// Failure
return QueryResult<OrderDto>.Fail(ResultStatus.NotFound, "Order not found");
Client Messaging
ClientMessage
Contract for server-to-client event messages:
| Property | Type | Description |
|---|---|---|
CorrelationId |
Guid |
Request correlation ID for tracing |
ContractAssemblyName |
string |
Assembly containing the message type |
ContractFullClassName |
string |
Full class name of the message type |
MessageJson |
string |
Serialized message content |
Constants
RequestHeaders
HTTP request header names used across Lewee applications:
CorrelationId- The HTTP header name for correlation ID ("X-Correlation-ID")
LoggingConsts
Property names for structured logging:
CorrelationId- Property name for correlation ID in logs ("CorrelationId")CorrelationIdHeaderKey- Header key for correlation ID in logging context ("correlationId")TenantId- Property name for tenant ID in multi-tenant applications ("TenantId")RequestType- Property name for request type classification ("RequestType")
HttpContextConsts
Constants for HTTP context items:
ClientId- Key for storing client ID in HTTP context ("SignalR-Client-Id")
Extension Methods
EnumExtensions
Utility methods for working with enum values:
GetDescription(this Enum value)- Gets theDescriptionAttributedescription from an enum value if it exists, otherwise returnsToString()of the valueIsEquivalentToZero<TEnum>(this TEnum value)- Determines whether the enum value is equivalent to zero
Usage
Working with Result Types
using Lewee.Common;
// In a command handler
public async Task<CommandResult> Handle(CreateOrderCommand command, CancellationToken ct)
{
if (!await this.repository.ExistsAsync(command.CustomerId, ct))
{
return CommandResult.Fail(ResultStatus.NotFound, "Customer not found");
}
var order = new Order(command.CustomerId);
await this.repository.AddAsync(order, ct);
return CommandResult.Success();
}
// In a query handler
public async Task<QueryResult<OrderDto>> Handle(GetOrderQuery query, CancellationToken ct)
{
var order = await this.repository.RetrieveByIdAsync(query.OrderId, ct);
if (order == null)
{
return QueryResult<OrderDto>.Fail(ResultStatus.NotFound, "Order not found");
}
return QueryResult<OrderDto>.Success(new OrderDto(order));
}
Working with Enum Descriptions
using Lewee.Common;
using System.ComponentModel;
public enum OrderStatus
{
[Description("Order Pending")]
Pending = 0,
[Description("Order Confirmed")]
Confirmed = 1,
Cancelled = 2
}
// Usage
var status = OrderStatus.Pending;
string description = status.GetDescription(); // Returns "Order Pending"
var cancelledStatus = OrderStatus.Cancelled;
string cancelledDescription = cancelledStatus.GetDescription(); // Returns "Cancelled" (ToString())
Using Standard Headers and Logging Constants
using Lewee.Common;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
// HTTP Headers
public void AddCorrelationHeader(HttpContext context, string correlationId)
{
context.Request.Headers[RequestHeaders.CorrelationId] = correlationId;
}
// Structured Logging
public void LogWithCorrelation(ILogger logger, string correlationId, string message)
{
using (logger.BeginScope(new Dictionary<string, object>
{
[LoggingConsts.CorrelationId] = correlationId
}))
{
logger.LogInformation(message);
}
}
Integration with Other Lewee Packages
This package is referenced by other Lewee packages to ensure consistent:
- Result type handling across commands and queries
- Client-server messaging via event broadcasting
- Correlation ID handling across HTTP requests and logging
- Multi-tenant logging patterns
The types and constants defined here are used by:
Lewee.Domain- References for domain abstractionsLewee.Application- Uses result types for command/query responsesLewee.Infrastructure.Auth- Uses authenticated user service interfaceLewee.Infrastructure.Correlate- Uses correlation ID constantsLewee.Infrastructure.Fluxor- Uses constants for logging and client event handling
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- FluentValidation (>= 12.2.0)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on Lewee.Common:
| Package | Downloads |
|---|---|
|
Lewee.Domain
Package Description |
|
|
Lewee.Infrastructure.Correlate
Package Description |
|
|
Lewee.Infrastructure.Refit
Package Description |
|
|
Lewee.Infrastructure.ServerEvents
Package Description |
|
|
Lewee.Infrastructure.Fluxor
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.40.3 | 81 | 11/22/2026 |