DomainGuard 1.0.3

dotnet add package DomainGuard --version 1.0.3
                    
NuGet\Install-Package DomainGuard -Version 1.0.3
                    
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="DomainGuard" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DomainGuard" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="DomainGuard" />
                    
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 DomainGuard --version 1.0.3
                    
#r "nuget: DomainGuard, 1.0.3"
                    
#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 DomainGuard@1.0.3
                    
#: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=DomainGuard&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=DomainGuard&version=1.0.3
                    
Install as a Cake Tool

DomainGuard is a lightweight, high-performance guard clause library designed specifically for:

  • Domain-Driven Design (DDD)
  • Clean Architecture
  • Enterprise applications
  • Value Objects, Aggregates, Entities, Domain Services
  • High-performance APIs and microservices

Key Principles

Zero dependencies
DomainGuard does not rely on external packages such as FluentValidation. It is intentionally minimal.

Zero allocations
Only pure value checks. No memory pressure, no object creation.

Modern Generic Math API
Uses .NET INumber<T> for universal numeric validation without boxing.

Expressive Errors
Errors are automatically enriched using CallerArgumentExpression.

Fast
Pure inlineable guard clauses with no reflection, no attributes, no scanning.


๐Ÿš€ Usage

Install via NuGet

dotnet add package DomainGuard

Basic Examples

using DomainGuard;

// Null Checks
name.EnsureNonNull();
address.EnsureNull();

// Default Checks
id.EnsureNotDefault();

// Numeric Checks
quantity.EnsurePositive();
balance.EnsureNonNegative();
amount.EnsureGreaterThan(5);
price.EnsureWithinRange(0, 100);

// String Checks
email.EnsureValidEmail();
title.EnsureNonBlank();
fileUrl.EnsureImageUrl();
sku.EnsureMatchesPattern(@"^[A-Z0-9]+$");

// Collections
items.EnsureAny();
collection.EnsureNonEmpty();

// Enums
status.EnsureEnumValueDefined();

// Dictionaries
dict.EnsureKeyExists("key");

// Booleans
isValid.EnsureTrue();
isDeleted.EnsureFalse();

Value Object Example

public sealed class ProductName
{
    public string Value { get; }

    public ProductName(string value)
    {
        Value = value
            .EnsureNonBlank()
            .EnsureLengthInRange(3, 100);
    }
}

Aggregate Example

public void ChangePrice(decimal newPrice)
{
    newPrice.EnsurePositive();

    Price = newPrice;
}

๐Ÿงช Unit Tests

DomainGuard includes full test coverage with:

  • xUnit
  • FluentAssertions
  • Coverage via Coverlet + ReportGenerator

Naming style:

MethodName_WhenCondition_ShouldExpectedBehavior

Example:

EnsurePositive_WhenValueIsGreaterThanZero_ShouldReturnValue()

๐ŸŽฏ Why DomainGuard?

Feature Benefit
Zero Dependencies No heavy packages, minimalistic and clean
Fast No reflection, no boxing
CallerArgumentExpression Beautiful domain error messages
Generic Math (INumber<T>) Universal numeric rule support
100% tested Confidence in production
Designed for DDD Perfect for Value Objects & Aggregates
NuGet-ready Metadata, docs, CI/CD

๐Ÿ‘ฅ Contributors

Name Role
Tural Suleymani Author, Maintainer

๐Ÿ“„ License

This project is licensed under the MIT License.
See the LICENSE file for details.


๐Ÿ’ฌ Support


โญ If you like DomainGuard...

Please star the repo on GitHub . It helps visibility and supports future development!

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 was computed.  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 was computed.  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.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 473 12/9/2025