StrongOf helps to implement primitives as a strong type that represents a domain object (e.g. UserId, EmailAddress, etc.). It is a simple class that wraps a value and provides a few helper methods to make it easier to work with. In contrast to other approaches, StrongOf is above all simple and performant - and not over-engineered.
Get Started
| Product | Versions |
|---|---|
| .NET |
README
StrongOf.Domains
Predefined strongly-typed domain models based on StrongOf for common use cases.
The namespace structure is deliberately designed so that namespace names do not collide with common class names you might use in your own codebase (e.g. Address, Person, Network).
NativeAOT
This package enables AOT/trimming analysis and is included in the native smoke test. Domain factories and generated regular expressions do not require runtime code generation. Operations such as time-zone lookup still depend on the operating system's data.
For JSON, domain types are already compiled, so property-level StrongOf.Json converters may be used
alongside a generated JsonSerializerContext. See the
JSON example.
Available Domain Types
| Namespace | Types |
|---|---|
StrongOf.Domains.Identity |
CorrelationId, EntityId, TenantId, Token, Username |
StrongOf.Domains.People |
Age, BirthYear, DateOfBirth, FirstName, FullName, LastName, MiddleName, PhoneNumber |
StrongOf.Domains.Postal |
City, CountryCode, CountryName, HouseNumber, Street, ZipCode |
StrongOf.Domains.Geography |
GeoCoordinate, Latitude, Longitude |
StrongOf.Domains.Networking |
EmailAddress, HostName, HttpMethod, IpAddress, MacAddress, Port, Url |
StrongOf.Domains.Finance |
CurrencyCode, Iban, Percentage |
StrongOf.Domains.Commerce |
Priority, Quantity, Sku |
StrongOf.Domains.Localization |
LanguageCode, Locale, TimeZoneId |
StrongOf.Domains.Measurement |
HeightCm, TemperatureCelsius, WeightKg |
StrongOf.Domains.Media |
ColorHex, FileExtension, FilePath, Isbn, MimeType, Slug |
StrongOf.Domains.Software |
SemVer |
Recommended: Global Usings
Add a single GlobalUsings.cs to your project to avoid per-file using directives:
// GlobalUsings.cs
global using StrongOf.Domains.Identity;
global using StrongOf.Domains.People;
global using StrongOf.Domains.Postal;
global using StrongOf.Domains.Geography;
global using StrongOf.Domains.Networking;
global using StrongOf.Domains.Finance;
global using StrongOf.Domains.Commerce;
global using StrongOf.Domains.Localization;
global using StrongOf.Domains.Measurement;
global using StrongOf.Domains.Media;
global using StrongOf.Domains.Software;
Key Features
- Format validation via
IsValidFormat()for types with format constraints (e.g.EmailAddress,CountryCode,Iban) - Safe factory via
TryCreate(string?, out T?)- returnsfalseinstead of creating an invalid instance - Range validation via
IsValidRange()for numeric and geographic types - Conversion helpers e.g.
ToMeters(),ToFahrenheit(),ToKelvin(),ToCultureInfo(),TryGetTimeZone() - Case-insensitive equality for
CountryCode,CurrencyCode,LanguageCode,Locale,FileExtension,MimeType,HostName,MacAddress
Usage
// Create domain objects
EmailAddress email = new("[email protected]");
bool isValidEmail = email.IsValidFormat();
// Safe factory - does not create an invalid instance
bool created = EmailAddress.TryCreate("bad-input", out EmailAddress? result); // false
CountryCode country = new("US");
CurrencyCode currency = new("USD");
GeoCoordinate berlin = GeoCoordinate.From(52.52m, 13.405m);
bool inRange = berlin.IsValidRange();
// Temperature conversion
TemperatureCelsius temp = new(100m);
decimal fahrenheit = temp.ToFahrenheit(); // 212
Installation
dotnet add package StrongOf.Domains
Downloads by Version
Similar & Alternative Packages
Hand-picked matching NuGet libraries based on tags & ecosystem
Depended On By
Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.