Repository navigation
v8.0.0
Motiv 8.0.0
Motiv 8.0.0 is a major release headlined by expression-tree propositions — write an ordinary boolean lambda and let Motiv decompose it into explainable, composable clauses — alongside new side-effect observers, a sharper evaluation API, and first-class IDE tooling that nudges you away from boolean blindness as you type.
✨ Highlights
Expression-tree propositions — Spec.From(...)
Build a proposition straight from a boolean expression. Motiv walks the expression tree and turns each sub-expression into its own clause, so a single lambda yields a full, de-noised explanation of why a result was true or false — no manual .And()/.Or() wiring required.
var canAccess = Spec
.From((User user) =>
user.Age >= 18 &
user.HasValidId &
(user.Country == "US" || user.HasInternationalPermit) &
!user.IsRestricted)
.Create("can access");
var result = canAccess.Evaluate(user);
result.Satisfied; // false
result.Assertions; // e.g. ["user.Age < 18", "user.HasValidId == false"]What you get inside a Spec.From(...) lambda:
- Automatic clause decomposition with auto-negated assertions for the unsatisfied branch.
- Inline
Any/All—numbers.Any(n => n % 2 == 0)andnumbers.All(n => n > 0)become higher-order propositions. - Compose existing specs — reference a
SpecBasedirectly inside the lambda and its assertions fold into the result. - The full builder chain —
WhenTrue,WhenFalse,WhenTrueYield,WhenFalseYieldall work afterSpec.From(...), exactly as withSpec.Build(...). Display.AsValue(...)— surface a sub-expression's runtime value in the assertion (e.g.user.Age = 15) instead of just the identifier.
A Expression<Func<TModel, bool>>.ToSpec() extension is also available for converting an already-materialized expression.
Side-effect observers — Tap, TapWhenTrue, TapWhenFalse
Attach callbacks (logging, metrics, auditing) to a proposition without changing how it evaluates or what it reports. Reason, Assertions, Justification, and Description pass through unchanged.
var observed = isEligible
.TapWhenTrue((customer, result) => logger.LogInformation("eligible: {Reason}", result.Reason))
.TapWhenFalse((customer, result) => logger.LogWarning("ineligible: {Reason}", result.Reason));Callbacks fire on Evaluate(...). The lightweight Matches(...) path intentionally does not invoke them.
🛠️ IDE tooling (ships in the box)
The Motiv.Analyzer and Motiv.CodeFix Roslyn components are bundled inside the Motiv package — no separate install. They activate automatically when you reference Motiv.
MOTIV0001analyzer — anInfo-level hint flagging raw boolean expressions (comparisons,&&/||/!,is/pattern checks) that could become Motiv propositions. It stays quiet inside existingSpec.Build(...)lambdas andSpecBase-derived types, so Motiv-aware code isn't nagged.- Code fix: "Convert to Motiv specification" — generates a
Spec.From(...)-based proposition from the flagged expression, with context-aware clause naming. Handles instance/static method calls,nameof(), pattern variables, and nested expressions, and supports Fix-All. - Code fix: "Convert to Motiv specification (with debug output)" — the same conversion wrapped with
.Tap()+Debug.WriteLine(conditional onDEBUG, so it's stripped from Release builds).
⚠️ API changes & migration
IsSatisfiedBy(model)is now[Obsolete]in favor ofEvaluate(model)(returns the richBooleanResultBase). The old method still compiles as a shim but emits a warning.- var result = spec.IsSatisfiedBy(model); + var result = spec.Evaluate(model);
Matches(model)is the new canonical boolean-only path — use it where you previously wrote.IsSatisfiedBy(model).Satisfied. It skips result-object allocation and does not triggerTapcallbacks.SpecBase<TModel>also exposes an implicit conversion toFunc<TModel, bool>backed byMatches.- if (spec.IsSatisfiedBy(model).Satisfied) { ... } + if (spec.Matches(model)) { ... }
These are the only changes 7.x consumers need to act on — and both old forms still work, so you can migrate at your own pace.
🚀 Platform & packaging
- .NET 10 support added — the package now targets
net8.0,net9.0,net10.0, andnetstandard2.0. - Symbol packages + SourceLink —
.snupkgsymbols ship alongside the package and SourceLink is enabled, so you can step straight into Motiv source while debugging. - Package icon now displays on nuget.org.
⚡ Performance
Result and description properties (Reason, Justification, Detailed, Statement, and the underlying result collections) are now lazily computed and cached, reducing work for evaluations that don't inspect every property.
🔧 Internal
- The source-generator attributes that produce the fluent builder overloads moved from a bundled package to the public Converj 2.0.0 dependency. This is a build-time change only — Motiv's public API is unchanged.
Full Changelog: https://github.com/karlssberg/Motiv/commits/v8.0.0