Skip to main content

Curiosus.Tools

NuGet Downloads Coverage

Foundation library of the Curiosus packages: basic helpers, models and small services with few dependencies (logging and DI abstractions, Curiosus.Configuration, NodaTime, MemoryPools). Most other Curiosus packages build on it.

Installation​

dotnet add package Curiosus.Tools

Usage​

using Curiosus.Tools;
using Curiosus.Tools.AppInitializer;
using Curiosus.Tools.TempFiles;

// startup: DI registrations
services.AddLocalDateTimeService(); // IDateTimeService over the local clock
services.AddTempFileServices(new TempFileOptions()); // ITempFileStreamFactory in ./.tmp
services.AddAppInitializer<WarmUpCacheInitializer>(); // IAppInitializer, run on start by Curiosus.Hosting

// unique 64-bit ids based on time; generatorId must differ between running processes
UniqueIdGenerator.Initialize(generatorId: 1);
long id = UniqueIdGenerator.Generate();
string publicId = id.ToPublicId();

// operation results
Response<Order> result = Response.Successful(order);
Response<Order> failed = Response.Failed<Order>(404, "Order not found");

// background work without losing exceptions
SendNotificationAsync(order).WithExceptionLogger(logger);

// hide secrets before logging JSON
var json = new SensitiveDataProtector("password").HideInJson(requestJson);

Main areas:

  • App lifecycle — IAppInitializer + AddAppInitializer, FireAndForget, ApplicationHelper, EnvironmentHelper.
  • Ids and hashing — UniqueIdGenerator, PublicId, UniqueKeyGenerator, XXHasher.
  • Date and time — IDateTimeService, DateTimePeriod, NullableDateTimePeriod, DateTimeHelper, TimeZoneHelper (NodaTime).
  • Models — Response/Response<T>, Error, Page, PaginationResponse.
  • Text — string/StringBuilder extensions, PhoneHelper, Transliteration, WebAddressValidator, SensitiveDataProtector, file size humanization.
  • Collections and threading — CircularBuffer, list/dictionary/hash set extensions, DynamicSemaphoreSlim.
  • Diagnostics — PerformanceManager.Measure and StuckCodeManager.Enter (call their Initialize(logger) first).
  • IO and HTTP — temp file streams, stream extensions, IHttpRequestParamsCalculator for size-based timeouts.

See the sample app for phone, transliteration and sensitive data examples.

See also​