Repository navigation
Web and Data
Both packages are opt-in so console apps and class libraries installing Ferrous do not pull ASP.NET Core or EF Core transitively.
dotnet add package Ferrous.AspNetCoreMap Result<T, TError> and Option<T> directly to IResult (200 OK, 404 Not Found, or RFC 7807 ProblemDetails). When TError is a ContextError, the full causal chain is preserved in detail and in the errorChain extension field:
using Ferrous.AspNetCore;
using Ferrous.Results;
app.MapGet("/albums/{id}", async (AlbumId id, AlbumService svc) =>
(await svc.FindAlbumAsync(id))
.ToHttpResult(notFoundDetail: $"Album {id.Value} was not found."));
app.MapPost("/orders", async (CreateOrderRequest req, OrderService svc) =>
(await svc.PlaceOrderAsync(req))
.WithContext("checkout failed")
.ToHttpResult(StatusCodes.Status422UnprocessableEntity));Attach .WithFerrousResults() to an endpoint or route group so handlers can return Result<T, TError> or Option<T> directly (zero reflection, NativeAOT-compatible):
var api = app.MapGroup("/api").WithFerrousResults();
api.MapGet("/tracks/{id}", (TrackId id) => repo.FindTrack(id)); // returns Option<Track>
api.MapPost("/tracks", (CreateTrack cmd) => repo.Create(cmd)); // returns Result<Track, ContextError>Register .AddFerrousOpenApi() so [Newtype], NonEmptyString, NonZero<T>, and [DiscriminatedUnion] emit clean primitive OpenAPI schemas (int32, uuid, string with minLength: 1) instead of wrapper objects:
builder.Services.AddOpenApi(options => options.AddFerrousOpenApi());dotnet add package Ferrous.EntityFrameworkCoreRegister built-in converters for NonEmptyString and NonZero<T> in ConfigureConventions, and wire reflection-free [Newtype] converters per property:
using Ferrous.EntityFrameworkCore;
public sealed class MusicDbContext(DbContextOptions<MusicDbContext> options) : DbContext(options)
{
public DbSet<Album> Albums => Set<Album>();
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
=> configurationBuilder
.UseFerrousConventions()
.UseFerrousNewtypes<MusicDbContext>(); // auto-discovers all [Newtype] structs in the assembly!
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Album>(e =>
{
e.HasKey(a => a.Id);
e.Property(a => a.Id).HasNewtypeConversion(id => id.Value, raw => new AlbumId(raw));
});
}
}Replace FirstOrDefaultAsync (null / default(T) ambiguity) and SingleAsync (throws InvalidOperationException) with explicit, value-type-safe helpers:
Option<Album> maybeAlbum = await db.Albums.FirstOrOptionAsync(a => a.Id == id, ct);
Result<Album, string> album = await db.Albums.SingleOrErrAsync(
a => a.Title == title,
notFoundError: () => "Album not found",
multipleFoundError: () => "Multiple albums matched",
ct);Ferrous — Rust quality-of-life primitives, source generators, and analyzers for .NET (.NET 10 / .NET 11, NativeAOT-ready, MIT License).