OrionGuard 6.4.2

dotnet add package OrionGuard --version 6.4.2
                    
NuGet\Install-Package OrionGuard -Version 6.4.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OrionGuard" Version="6.4.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OrionGuard" Version="6.4.2" />
                    
Directory.Packages.props
<PackageReference Include="OrionGuard" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OrionGuard --version 6.4.2
                    
#r "nuget: OrionGuard, 6.4.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OrionGuard@6.4.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OrionGuard&version=6.4.2
                    
Install as a Cake Addin
#tool nuget:?package=OrionGuard&version=6.4.2
                    
Install as a Cake Tool

OrionGuard

A modern, fluent, and extensible guard clause & validation library for .NET 8/9/10.

Features

  • Fluent API — Ensure.That(email).NotNull().Email()
  • Security Guards — SQL injection, XSS, path traversal, command injection, LDAP, XXE
  • Format Guards — Coordinates, MAC, CIDR, JWT, country codes, time zones, Base64
  • FastGuard — Span-based zero-allocation validation with ThrowHelper optimization
  • Result Pattern — Collect all errors with GuardResult.Combine()
  • Async Validation — Database lookups, API calls
  • Object Validation — Property expressions, cross-property rules, compiled caching
  • Business Guards — Money, SKU, coupon, scheduling, status transitions
  • Attribute-Based — [NotNull], [Email], [Range] on model properties
  • DI Support — services.AddOrionGuard()
  • Localization — 9 languages, thread-safe per-request culture

Quick Start

using Moongazing.OrionGuard.Core;
using Moongazing.OrionGuard.Extensions;

Ensure.That(email).NotNull().NotEmpty().Email();
FastGuard.NotNullOrEmpty(name, nameof(name));
userInput.AgainstInjection(nameof(userInput));
"US".AgainstInvalidCountryCode(nameof(country));

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (16)

Showing the top 5 NuGet packages that depend on OrionGuard:

Package Downloads
OrionGuard.AspNetCore

ASP.NET Core integration for OrionGuard validation library. Provides middleware, Minimal API endpoint filters, MVC action filters, and RFC 9457 ProblemDetails support.

OrionGuard.MediatR

MediatR integration for OrionGuard validation library. Provides ValidationBehavior pipeline behavior for automatic request validation in CQRS pipelines.

OrionGuard.Swagger

Swagger/OpenAPI integration for OrionGuard. Auto-generates OpenAPI constraints from OrionGuard validation attributes.

OrionGuard.Blazor

Blazor integration for OrionGuard validation library. Provides EditForm validation, custom validation components, and data annotations interop.

OrionGuard.SignalR

SignalR integration for OrionGuard validation library. Provides Hub filter for automatic method parameter validation.

GitHub repositories

This package is not used by any popular GitHub repositories.

v6.3.0 — Release Notes

NEW: Domain event dispatcher — IDomainEventDispatcher and IDomainEventHandler<TEvent> abstractions. Default ServiceProviderDomainEventDispatcher resolves handlers from IServiceProvider; supports SequentialFailFast (default), SequentialContinueOnError, and Parallel dispatch modes. DI: services.AddOrionGuardDomainEvents() + services.AddOrionGuardDomainEventHandlers(assembly).

NEW: MediatR bridge (OrionGuard.MediatR) — MediatRDomainEventDispatcher delegates to MediatR's IPublisher. Consumer events opt in by adding ': INotification' to their record declaration; the bridge throws InvalidOperationException for events that don't. No wrapper types — handlers stay as natural INotificationHandler<TEvent>. DI: services.AddOrionGuardMediatRDomainEvents() swaps the registered dispatcher.

NEW PACKAGE: OrionGuard.EntityFrameworkCore — DomainEventSaveChangesInterceptor pulls events from tracked IAggregateRoot instances at SavingChangesAsync. Two modes: Inline (default — dispatches post-commit) and Outbox (persists to OutboxMessage rows in the same transaction, dispatched by a hosted background worker). OutboxOptions configures PollingInterval / BatchSize / MaxRetries / TableName. Worker increments RetryCount on failure and dead-letters after MaxRetries. W3C trace context (TraceParent / TraceState) propagates across the outbox boundary so end-to-end traces span the worker. DI: services.AddOrionGuardEfCore<TDbContext>(o => o.UseInline() | o.UseOutbox()).

NEW PACKAGE: OrionGuard.Testing — DomainEventCapture and DomainEventAssertions for fluent unit-test assertions over aggregate-raised events. InMemoryDomainEventDispatcher for integration tests. Framework-agnostic — no xUnit / NUnit / FluentAssertions dependency. Throws DomainEventAssertionException, which any test runner treats as a failure.

NEW: OrionGuard.OpenTelemetry domain-event instrumentation — OrionGuardDomainEventTelemetry exposes ActivitySource and Meter under 'Moongazing.OrionGuard.DomainEvents', with counters orionguard.domain_events.dispatched / failed / outbox.processed / outbox.retries plus the orionguard.domain_events.duration histogram. InstrumentedDomainEventDispatcher decorator opens a span per dispatch and sets ActivityStatusCode.Error on exception. DI: services.WithOpenTelemetryDomainEvents() (call after AddOrionGuardDomainEvents()).

MIGRATION: No breaking changes from v6.2.0. Existing aggregates raise events the same way; nothing dispatches until AddOrionGuardDomainEvents() is wired. MediatR consumers add ', INotification' to their event records (one-line per event). Outbox consumers add an EF Core migration for the OrionGuard_Outbox table.

ROADMAP: v6.4.0 = BusinessRule base class + Guard.Against.BrokenRule + ASP.NET Core ProblemDetails mapping; distributed locking for multi-instance outbox workers; OutboxTypeMapRegistry (alias system for safe type renames); archival job. v6.5+ = push-based outbox dispatch (LISTEN/NOTIFY, SqlDependency); event sourcing primitives.

Full changelog: https://github.com/tunahanaliozturk/OrionGuard/blob/master/CHANGELOG.md

v6.2.0 — Release Notes

NEW: IStronglyTypedId<TValue> marker interface — implemented by both the StronglyTypedId<TValue> abstract record (manual style) AND source-generated readonly partial struct ids. The AgainstDefaultStronglyTypedId guard now accepts this interface as its receiver, so both id styles work with the same guard.

NEW: DomainEventBase abstract record — consumers can write `public sealed record OrderPlaced(OrderId Id) : DomainEventBase;` instead of hand-rolling EventId and OccurredOnUtc. Both properties use init accessors so tests can pin them via `with` expressions.

NEW: Generated strongly-typed ids implement IParsable<TSelf> and ISpanParsable<TSelf> — ASP.NET Core minimal APIs bind them from route/query/form parameters without a custom TypeConverter hop. Standard .NET FormatException semantics on Parse failure.

IMPROVED: The StronglyTypedId source generator now detects whether the consumer project references EF Core and skips emitting the ValueConverter companion when it does not — console apps, Blazor WASM, and class libraries no longer need a spurious EF Core PackageReference just to build.

PACKAGE RENAME: Sub-package NuGet PackageIds drop the 'Moongazing.' brand prefix — install as OrionGuard.AspNetCore, OrionGuard.Blazor, OrionGuard.Generators, OrionGuard.Grpc, OrionGuard.MediatR, OrionGuard.OpenTelemetry, OrionGuard.SignalR, OrionGuard.Swagger. The old Moongazing.OrionGuard.* package IDs remain on NuGet.org for v6.1.0 and earlier; v6.2.0 ships under the new names. C# namespaces are unchanged (using Moongazing.OrionGuard.AspNetCore; still works) so source code does not break.

MIGRATION: Source-compatible with v6.1.0 — no user code change required. Receiver and return type of AgainstDefaultStronglyTypedId widened to IStronglyTypedId<TValue> (manual records still implement this interface). Recompile recommended. Consumers should update their package references from Moongazing.OrionGuard.* to OrionGuard.* (same assemblies, same namespaces, new package IDs).

ROADMAP: v6.3.0 = domain event dispatcher + MediatR bridge + EF Core SaveChanges interceptor. v6.4.0 = full BusinessRule base class + Guard.Against.BrokenRule + AspNetCore ProblemDetails mapping.

Full changelog: https://github.com/tunahanaliozturk/OrionGuard/blob/master/CHANGELOG.md

v6.1.0 — Release Notes

NEW: DDD Domain Primitives — ValueObject (hybrid: abstract base + IValueObject marker for records), Entity<TId> with identity equality and CheckRule / CheckRuleAsync helpers, AggregateRoot<TId> with IAggregateRoot marker and PullDomainEvents() dispatching buffer.

NEW: StronglyTypedId<TValue> — abstract record base for manual ids, plus [StronglyTypedId<TValue>] incremental source generator (Moongazing.OrionGuard.Generators) that emits the partial struct body, EF Core ValueConverter, System.Text.Json JsonConverter, and TypeConverter for Guid, int, long, string, and Ulid (net9.0+).

NEW: AgainstDefaultStronglyTypedId — extension method that throws when a strongly-typed id is null or wraps the default of its underlying type.

NEW: services.AddOrionGuardStronglyTypedIds() — scans assemblies for generated EF Core converters and registers them.

NEW: IDomainEvent, IBusinessRule, IAsyncBusinessRule, BusinessRuleValidationException, DomainInvariantException — abstractions landing in v6.1.0 so primitives are immediately usable; full base classes and dispatcher arrive in v6.2.0 and v6.3.0.

NEW: Localization — DefaultStronglyTypedId, BusinessRuleBroken, DomainInvariantViolated keys added for all 14 bundled languages.

Full changelog: https://github.com/tunahanaliozturk/OrionGuard/blob/master/CHANGELOG.md

v6.0.0 — Release Notes

NEW: GeneratedRegex Migration — All 20+ regex patterns migrated to .NET 8+ [GeneratedRegex] source-generated code. Zero runtime compilation, NativeAOT compatible.

NEW: 14-Language Localization — Added Chinese (zh), Korean (ko), Russian (ru), Dutch (nl), Polish (pl). Completed all 30 message keys for German, French, Spanish, Portuguese, Arabic, Japanese.

NEW: Rate Limit Guards — AgainstRateLimitExceeded(), AgainstTooManyRequests(), AgainstSlidingWindowExceeded(), AgainstConcurrentLimitExceeded(), AgainstDailyQuotaExceeded().

NEW: IRequestValidator interface — Pipeline-ready validator interface for ASP.NET Core and MediatR integration.

NEW: GuardResult.SuggestedHttpStatusCode — HTTP status code hints for ProblemDetails responses.

NEW PACKAGE: Moongazing.OrionGuard.AspNetCore — Middleware, Minimal API endpoint filters (.WithValidation), MVC filters, RFC 9457 ProblemDetails, IExceptionHandler.

NEW PACKAGE: Moongazing.OrionGuard.MediatR — ValidationBehavior pipeline behavior for automatic CQRS request validation.

NEW PACKAGE: Moongazing.OrionGuard.Generators — Compile-time source generator for reflection-free NativeAOT validation. Roslyn analyzers included.

NEW PACKAGE: Moongazing.OrionGuard.Swagger — Auto-generate OpenAPI constraints from OrionGuard validation attributes.

NEW PACKAGE: Moongazing.OrionGuard.OpenTelemetry — Validation metrics and distributed tracing spans.

DEPRECATED: RegexPatterns class — Use GeneratedRegexPatterns instead.

Full changelog: https://github.com/tunahanaliozturk/OrionGuard/blob/master/CHANGELOG.md

v5.0.1 — Previous Release Notes

NEW: Security Guards — SQL injection, XSS, path traversal, command injection, LDAP injection, XXE detection, unsafe filename, and open redirect validation. All patterns use FrozenSet for O(1) lookups.

NEW: Format Guards (replaces TurkishGuards) — Geographic coordinates, MAC address, hostname (RFC 1123), CIDR notation, ISO 3166-1 country codes, IANA time zones, BCP 47 language tags, JWT structure, connection strings, and Base64 validation.

NEW: ThrowHelper Pattern — All hot-path guards delegate throwing to a centralized ThrowHelper with [DoesNotReturn] and [StackTraceHidden] for smaller JIT-compiled method bodies and cleaner stack traces.

NEW: Span-Based FastGuard — Email, ASCII, AlphaNumeric, NumericString, MaxLength, ValidGuid, and Finite validators using ReadOnlySpan with zero allocations.

IMPROVED: Thread-Safe Localization — Rewritten with ConcurrentDictionary and AsyncLocal. Now supports 8 languages: EN, TR, DE, FR, ES, PT, AR, JA. Per-request culture scoping via SetCultureForCurrentScope.

IMPROVED: ObjectValidator — Compiled expression caching, CrossProperty validation, conditional When() blocks.

IMPROVED: FluentGuard — Transform() and Default() pipeline methods. All date comparisons use DateTime.UtcNow.

IMPROVED: All exceptions are sealed with ErrorCode and ParameterName properties.

IMPROVED: RegexCache with bounded size (1000), FrozenSet for BusinessGuards currency codes, ICollection.Count optimization in CollectionGuards.

FIXED: AgainstNotAllLowercase was comparing string to itself (always passed).
FIXED: AgainstEmptyCollection was throwing EmptyStringException instead of NullValueException.
FIXED: GuardBuilderExtensions was passing .Value instead of .ParameterName.

BREAKING: Validate.Object renamed to Validate.For. FastGuard.Guid renamed to FastGuard.ValidGuid. TurkishGuards removed.

Full changelog: https://github.com/tunahanaliozturk/OrionGuard/blob/master/CHANGELOG.md