Getting started with Pineapple
Pineapple installs from NuGet and needs no configuration. Add the package, import a namespace, and call the helpers directly.
1. Install
dotnet add package Pineapple
Requirements: .NET 8 or .NET 10. For SQL Server helpers, also add Pineapple.Data (see Pineapple.Data).
2. Validate arguments with guard clauses
Import Preconditions statically so checks read like assertions:
using static Pineapple.Common.Preconditions;
public void Ship(string sku, int quantity, Uri callback)
{
CheckIsNotNullOrWhitespace(nameof(sku), sku); // ArgumentNullException / ArgumentException
CheckIsNotLessThan(nameof(quantity), quantity, 1); // ArgumentOutOfRangeException
CheckIsNotNull(nameof(callback), callback);
}
3. Shorten identifiers with ShortGuid
using Pineapple.Common;
ShortGuid id = Guid.NewGuid();
string slug = id; // 22 URL-safe characters
Guid back = new ShortGuid(slug); // round-trips to the same Guid
4. Rate-limit a dependency
using Pineapple.Threading;
var governor = new ResourceGoverner(maxCallsPerMinute: 120);
foreach (var item in items)
{
await using (await governor.GetOperationScopeAsync())
{
await api.SendAsync(item);
}
}
5. Time an operation
using Pineapple.Diagnostics;
using (new TimingScope("LoadCustomers", logger))
{
customers = await repository.LoadAsync();
}
// Debug log: Operation [LoadCustomers] called from [Handle] took 42.17ms