Mostlylucid.Common
6.3.8
See the version list below for details.
dotnet add package Mostlylucid.Common --version 6.3.8
NuGet\Install-Package Mostlylucid.Common -Version 6.3.8
<PackageReference Include="Mostlylucid.Common" Version="6.3.8" />
<PackageVersion Include="Mostlylucid.Common" Version="6.3.8" />
<PackageReference Include="Mostlylucid.Common" />
paket add Mostlylucid.Common --version 6.3.8
#r "nuget: Mostlylucid.Common, 6.3.8"
#:package Mostlylucid.Common@6.3.8
#addin nuget:?package=Mostlylucid.Common&version=6.3.8
#tool nuget:?package=Mostlylucid.Common&version=6.3.8
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.ActivitySourceTelemetryOptions- Configuration for telemetry behaviorTelemetryConstants- Standard attribute names following OpenTelemetry semantic conventionsTelemetryExtensions- Helper methods for service registrationActivityExtensions- Extension methods for recording results and exceptions
Installation
dotnet add package Mostlylucid.Common
License
Unlicense (Public Domain)
| Product | Versions 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. |
-
net10.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.9)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Caching.Memory (>= 10.0.7)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Options (>= 10.0.7)
-
net8.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.9)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Caching.Memory (>= 10.0.7)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Options (>= 10.0.7)
-
net9.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.9)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Caching.Memory (>= 10.0.7)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Options (>= 10.0.7)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Mostlylucid.Common:
| Package | Downloads |
|---|---|
|
mostlylucid.geodetection
DEPRECATION NOTICE: This package will be renamed to 'stylobot.geodetection' on June 1 2025. See https://github.com/scottgal/stylobot/blob/main/docs/migration-v7.md 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.6.0-alpha1 | 0 | 5/18/2026 |
| 6.5.3 | 29 | 5/17/2026 |
| 6.5.2 | 32 | 5/17/2026 |
| 6.5.1-rc3 | 36 | 5/17/2026 |
| 6.5.1-rc2 | 33 | 5/17/2026 |
| 6.5.1-rc1 | 37 | 5/17/2026 |
| 6.5.1-rc0 | 47 | 5/17/2026 |
| 6.5.0-rc1 | 49 | 5/17/2026 |
| 6.5.0-rc0 | 39 | 5/16/2026 |
| 6.4.7-rc3 | 36 | 5/16/2026 |
| 6.4.7-rc2 | 31 | 5/16/2026 |
| 6.4.7-rc1 | 38 | 5/15/2026 |
| 6.4.6 | 43 | 5/15/2026 |
| 6.4.5 | 51 | 5/14/2026 |
| 6.4.5-rc3 | 28 | 5/17/2026 |
| 6.4.5-rc2 | 33 | 5/17/2026 |
| 6.4.4 | 77 | 5/13/2026 |
| 6.4.3 | 74 | 5/13/2026 |
| 6.3.8 | 91 | 5/10/2026 |
| 4.7.6-rc0 | 41 | 5/15/2026 |