Lewee.Common 0.40.3

dotnet add package Lewee.Common --version 0.40.3
                    
NuGet\Install-Package Lewee.Common -Version 0.40.3
                    
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="Lewee.Common" Version="0.40.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lewee.Common" Version="0.40.3" />
                    
Directory.Packages.props
<PackageReference Include="Lewee.Common" />
                    
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 Lewee.Common --version 0.40.3
                    
#r "nuget: Lewee.Common, 0.40.3"
                    
#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 Lewee.Common@0.40.3
                    
#: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=Lewee.Common&version=0.40.3
                    
Install as a Cake Addin
#tool nuget:?package=Lewee.Common&version=0.40.3
                    
Install as a Cake Tool

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 the DescriptionAttribute description from an enum value if it exists, otherwise returns ToString() of the value
  • IsEquivalentToZero<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 abstractions
  • Lewee.Application - Uses result types for command/query responses
  • Lewee.Infrastructure.Auth - Uses authenticated user service interface
  • Lewee.Infrastructure.Correlate - Uses correlation ID constants
  • Lewee.Infrastructure.Fluxor - Uses constants for logging and client event handling
Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (7)

Showing the top 5 NuGet packages that depend on Lewee.Common:

Package Downloads
Lewee.Domain

Package Description

Lewee.Infrastructure.Auth

Package Description

Lewee.Infrastructure.Correlate

Package Description

Lewee.Infrastructure.Fluxor

Package Description

Lewee.Infrastructure.Keycloak

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.40.3 68 11/22/2026