Codebelt

Cuemon.Extensions.Data.Integrity

Build cache validators from runtime metadata without manually wiring EntityInfo or checksum decorators.

.NET 10.0 / .NET 9.0 MIT v10.5.3 65,168 downloads

Overview

Cuemon.Extensions.Data.Integrity adds extension methods on top of Cuemon.Data.Integrity so callers can create or enrich CacheValidator instances from values they already have, including Assembly, FileInfo, DateTime, and existing ChecksumBuilder instances. It removes most of the manual EntityInfo construction and checksum decorator plumbing from call sites.

The package does not introduce a new integrity model. It packages common validator creation patterns around the lower-level Cuemon.Data.Integrity types and keeps checksum composition fluent when a builder needs extra identity data.

Key APIs

AssemblyExtensions.GetCacheValidator creates a CacheValidator from an Assembly. For file-backed assemblies it reuses file-based validation and then combines the assembly full-name hash so the result reflects both the binary and the assembly identity.

FileInfoExtensions.GetCacheValidator converts file metadata into a CacheValidator by delegating to CacheValidatorFactory.CreateValidator. The optional setup callback lets callers tune FileChecksumOptions, and any file-processing failure falls back to CacheValidator.Default.

DateTimeExtensions.GetCacheValidator turns created and modified timestamps into a validator without forcing you to construct EntityInfo directly. The checksum-aware overload also lets you attach a precomputed digest and explicitly mark it as weak or strong validation.

ChecksumBuilderExtensions.CombineWith<T> adds strongly typed overloads for numeric values, strings, and byte arrays while preserving the concrete ChecksumBuilder subtype. It is the package-owned shortcut over the lower-level decorator-based combine operations in Cuemon.Data.Integrity.

Basic usage

using Cuemon.Data.Integrity;
using Cuemon.Extensions.Data.Integrity;
using Codebelt.Extensions.Xunit;
using Xunit;

namespace MyProject.Tests;

public class AssemblyCacheValidatorTest : Test
{
    public AssemblyCacheValidatorTest(ITestOutputHelper output) : base(output)
    {
    }

    [Fact]
    public void ShouldCreateWeakValidatorForCurrentAssembly()
    {
        var assembly = typeof(AssemblyCacheValidatorTest).Assembly;
        var validator = assembly.GetCacheValidator();

        Assert.Equal(EntityDataIntegrityValidation.Weak, validator.Validation);
        Assert.NotEqual(CacheValidator.Default.ToString(), validator.ToString());

        TestOutput.WriteLine($"Assembly validator: {validator}");
    }
}

Use this pattern when an assembly already represents the versioned artifact you need to fingerprint for cache validation or deployment-aware responses. It matters because the extension combines assembly identity with file-backed integrity data without forcing you to compose EntityInfo and checksum operations manually.

Installation

dotnet add package Cuemon.Extensions.Data.Integrity

Usage guidance

Adopt this package when your application naturally starts from assemblies, files, timestamps, or existing checksum builders and you want those values to flow into CacheValidator instances with minimal ceremony. If you already build EntityInfo yourself or need integrity primitives beyond these extension points, depend on Cuemon.Data.Integrity directly.

Family packages