How altmann/fluentresults works
Project Type and Purpose
• This is an open‑source .NET library (FluentResults) plus several sample applications and test projects.
• The core library implements a Result container pattern for success/failure.
• There are two official extensions (ASP.NET Core integration and FluentAssertions integration), example apps (MediatR, WebHost, Domain‑Driven Design, Hangfire, WebController) and unit/integration tests.
Directory‑Level Architecture Analysis
• Core Library ("FluentResults")
• src/FluentResults: core types (Result, Result<T>, Reasons, Factories, Logging, Settings, Extensions).
• Extensions
• src/FluentResults.Extensions.AspNetCore: maps Result to ASP.NET Core IActionResult.
• src/FluentResults.Extensions.FluentAssertions: Assertion helpers for FluentAssertions.
• Sample Applications
• src/FluentResults.Samples.MediatR: Razor Pages + MediatR pipeline + validation behavior + handlers.
• src/FluentResults.Samples.WebHost: ASP.NET Core controllers demonstrating custom EndpointProfile.
• src/FluentResults.Samples/DomainDrivenDesign: DDD command/handler sample.
• src/FluentResults.Samples/HangfireJobs: background job using Result.
• src/FluentResults.Samples/WebController: Web API controller + Result→DTO mapping.
• Tests
• src/FluentResults.Test: core library unit tests.
• src/FluentResults.Extensions.FluentAssertions.Test: tests for the FluentAssertions extension.
Key Components
a. FluentResults Core
• Packages: FluentResults.dll targeting .NET Standard.
• Modules: ResultBase, Result<T>, IReason/IError/ISuccess, factories, settings, logging interfaces.
b. Extension Modules
• AspNetCore extension: Result→ActionResult transformer, endpoint profiles.
• FluentAssertions extension: custom assertion operators.
c. Sample Apps
• MediatR sample:
• Pages/UI layer (Razor Pages)
• MediatR pipeline behaviors (validation)
• Command & Query handlers
• Uses FluentResults core and returns Result from handlers
• WebHost sample:
• ASP.NET Core Controllers
• Custom EndpointProfile injection
• DDD, Hangfire, WebController: simple domain handlers or controllers returning Results.
d. External Services & Frameworks
• ASP.NET Core WebHost
• MediatR library
• Hangfire
• FluentAssertions
e. Test Projects
• Core library tests
• Extension tests
Relationships and Data Flows
• All sample apps & tests → FluentResults.Core
• AspNetCore sample → FluentResults.Extensions.AspNetCore → FluentResults.Core
• Tests → corresponding projects (core or extension)
• FluentAssertions tests → FluentAssertions extension → FluentResults.Core
• Runtime Flow (e.g. ASP.NET Core sample):
HTTP Request → Controller → calls domain/service → returns Result → AspNetCoreResultTransformer → IActionResult → HTTP Response
• MediatR Flow:
UI Page → MediatR Request → ValidationPipelineBehavior → Handler returns Result → Razor Page displays Result
Architectural Patterns & Principles
• Separation of Concerns: Core library is independent of hosting technology.
• Extensibility via Extensions: ASP.NET Core and FluentAssertions support added by separate NuGet packages.
• Sample‑driven documentation: Multiple small apps demonstrate integration points.
• Dependency Injection: Extension profiles and loggers injected via Result.Setup or ASP.NET Core DI.
• Fluent Interface: chaining of methods (Ok, Fail, WithError, Map, Bind, Try, Log, etc.).
Checklist
• [ ] Core library module with sub‑packages (Results, Reasons, Logging, Settings).
• [ ] External frameworks (ASP.NET Core, MediatR, Hangfire, FluentAssertions).
• [ ] Optional zoom‑in callouts for critical flows (e.g., HTTP request → Result transformation).