Mostlylucid.Common 6.2.1

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

Mostlylucid.Common

Shared abstractions, base classes, and utilities for Mostlylucid NuGet packages.

Features

Caching

Generic caching service abstraction with memory cache implementation:

// Register caching service
services.AddMemoryCachingService<MyData>(options =>
{
    options.DefaultExpiration = TimeSpan.FromMinutes(30);
    options.MaxEntries = 5000;
});

// Use in your service
public class MyService
{
    private readonly ICachingService<MyData> _cache;

    public async Task<MyData?> GetDataAsync(string key)
    {
        return await _cache.GetOrAddAsync(key, async () =>
        {
            // Fetch from source if not cached
            return await FetchFromSourceAsync(key);
        });
    }
}

Statistics Tracking

Base interfaces and implementations for service statistics:

public class MyService : IServiceStatistics
{
    private readonly ServiceStatisticsTracker _stats = new();

    public async Task<Result> ProcessAsync(Request request)
    {
        _stats.IncrementRequests();

        var cached = GetFromCache(request);
        if (cached != null)
        {
            _stats.IncrementCacheHit();
            return cached;
        }

        // Process...
    }

    public long TotalRequests => _stats.TotalRequests;
    public long CacheHits => _stats.CacheHits;
    public double CacheHitRate => _stats.CacheHitRate;
}

Periodic Update Service

Base class for background services that periodically update data:

public class MyUpdateService : PeriodicUpdateService
{
    protected override TimeSpan UpdateInterval => TimeSpan.FromHours(24);

    protected override Task<DateTime?> GetLastUpdateTimeAsync(CancellationToken ct)
    {
        return Task.FromResult(File.GetLastWriteTimeUtc("data.db") as DateTime?);
    }

    protected override async Task PerformUpdateAsync(CancellationToken ct)
    {
        await DownloadLatestDataAsync(ct);
    }
}

Configuration Interfaces

Standard options interfaces for consistent configuration:

public class MyOptions : ICacheableOptions, ITestableOptions
{
    public bool Enabled { get; set; } = true;
    public TimeSpan CacheDuration { get; set; } = TimeSpan.FromHours(1);
    public int MaxCacheEntries { get; set; } = 10000;
    public bool EnableTestMode { get; set; } = false;
    public string TestModeHeader => "X-Test-Mode";
}

Middleware Base

Base class for middleware with test mode support:

public class MyMiddleware : TestModeMiddlewareBase<MyResult>
{
    protected override string ResultKey => "MyResult";
    protected override string TestModeHeader => "X-Test-Mode";
    protected override bool IsTestModeEnabled => _options.EnableTestMode;

    protected override MyResult? CreateTestModeResult(string testValue)
    {
        return new MyResult { TestValue = testValue };
    }

    protected override async Task<MyResult?> ProcessRequestAsync(HttpContext context)
    {
        var ip = context.GetClientIpAddress();
        return await _service.ProcessAsync(ip);
    }
}

IP Address Extraction

Helper for getting client IP addresses with proxy/CDN support:

// Automatically checks CF-Connecting-IP, X-Forwarded-For, X-Real-IP, etc.
var clientIp = context.GetClientIpAddress();

Entity Interfaces

Standard interfaces for database entities:

public class CachedItem : ICachedEntity
{
    public string Key { get; set; }
    public DateTime CreatedAt { get; set; }
    public DateTime UpdatedAt { get; set; }
    public DateTime ExpiresAt { get; set; }
    public bool IsExpired => DateTime.UtcNow > ExpiresAt;
}

OpenTelemetry Support

Base classes and helpers for OpenTelemetry instrumentation across all Mostlylucid packages:

using Mostlylucid.Common.Telemetry;

// Get all Mostlylucid activity source names for OpenTelemetry configuration
var sources = TelemetryExtensions.GetMostlylucidActivitySourceNames();
foreach (var source in sources)
{
    tracing.AddSource(source);
}

// Activity source names are available as constants
// ActivitySources.BotDetection = "Mostlylucid.BotDetection"
// ActivitySources.GeoDetection = "Mostlylucid.GeoDetection"
// etc.

Available telemetry utilities:

  • TelemetryActivitySource - Wrapper for System.Diagnostics.ActivitySource
  • TelemetryOptions - Configuration for telemetry behavior
  • TelemetryConstants - Standard attribute names following OpenTelemetry semantic conventions
  • TelemetryExtensions - Helper methods for service registration
  • ActivityExtensions - Extension methods for recording results and exceptions

Installation

dotnet add package Mostlylucid.Common

License

Unlicense (Public Domain)

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  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 is compatible.  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 (1)

Showing the top 1 NuGet packages that depend on Mostlylucid.Common:

Package Downloads
mostlylucid.geodetection

Geographic location detection and routing middleware for ASP.NET Core applications with country-based routing and IP geolocation.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.2.1 0 5/6/2026
6.2.0 0 5/6/2026
6.1.10 43 5/4/2026
6.1.9 41 5/3/2026
6.1.8 41 5/3/2026
6.1.7 41 5/3/2026
6.1.6 37 5/3/2026
6.1.5 39 5/3/2026
6.1.4 44 5/3/2026
6.1.3 42 5/3/2026
6.1.2 45 5/3/2026
6.1.1 44 5/3/2026
6.0.6 87 4/26/2026
6.0.5 84 4/26/2026
6.0.4-rc1 86 4/26/2026
6.0.3-beta17 87 4/26/2026
6.0.3-beta16 94 4/26/2026
6.0.3-beta15 86 4/26/2026
6.0.3-beta14 81 4/26/2026
6.0.3-beta13 77 4/25/2026
Loading failed