Rsft.Net.DomainParser
1.3.241
dotnet add package Rsft.Net.DomainParser --version 1.3.241
NuGet\Install-Package Rsft.Net.DomainParser -Version 1.3.241
<PackageReference Include="Rsft.Net.DomainParser" Version="1.3.241" />
<PackageVersion Include="Rsft.Net.DomainParser" Version="1.3.241" />
<PackageReference Include="Rsft.Net.DomainParser" />
paket add Rsft.Net.DomainParser --version 1.3.241
#r "nuget: Rsft.Net.DomainParser, 1.3.241"
#:package Rsft.Net.DomainParser@1.3.241
#addin nuget:?package=Rsft.Net.DomainParser&version=1.3.241
#tool nuget:?package=Rsft.Net.DomainParser&version=1.3.241
π Components Β· Domain Parser
.NET library that splits a domain name into TLD, second-level domain (SLD) and subdomain using the Public Suffix List.
β¨ What it does
Parsing domain names is not easy. In me.com.br, is the TLD br or com.br? The answer is com.br, but no simple rule in code can tell you that. Each registry has its own policy. So the PublicSuffix project keeps a list of every public suffix.
From PublicSuffix:
"Since there is no algorithmic method of finding the highest level at which a domain may be registered for a particular top-level domain (the policies differ with each registry), the only method is to create a list. This is the aim of the Public Suffix List."
This library loads that list and uses it to parse domains into TLD, SLD and subdomain.
flowchart LR
PSL["publicsuffix.org<br/>effective_tld_names.dat"]
LOCAL["Embedded copy<br/>Data/EffectiveTldNames.txt"]
CACHE["TldRulesCache<br/>(MemoryCache, 1 day)"]
LOGIC["Logic.DomainParser"]
SVC["Service.DomainParser"]
OUT["DomainInfo<br/>Tld Β· Sld Β· Subdomain"]
PSL --> CACHE
LOCAL -. "fallback if remote fails" .-> CACHE
CACHE --> LOGIC --> SVC --> OUT
| Component | Purpose |
|---|---|
DomainParserFactory |
Public entry point. Create(...) wires up and returns an IDomainParser<DomainInfo> |
PublicSuffixRepository |
Downloads the list over HTTP, with a timeout (default 8000 ms) |
LocalResourceRepository |
Reads the copy of the list embedded in the assembly |
TldRulesCache |
Loads rules (remote first, local on failure) and caches them in memory for one day |
TldRuleResolverPublicSuffix |
Turns a list line into a Normal, Wildcard (*.) or Exception (!) rule |
Logic.DomainParser |
Picks the longest matching rule and splits the domain |
Features:
- Caching. Rules are read once and kept in a
MemoryCachefor a day. - Fallback data. If the live list can't be fetched, the embedded copy is used.
- Extensible. Supply your own rule source or configuration to
Create(...).
π¦ Using this package
Package ID: Rsft.Net.DomainParser (targets netstandard2.0). It depends on Rsft.Net.DomainParser.Core, which holds the public interfaces and entities.
dotnet add package Rsft.Net.DomainParser
Quick start
// Create an instance of the domain parser using the internal defaults
var domainParser = DomainParserFactory.Create();
// Parse the domain name
var domainInfo = domainParser.Parse("h1.mydomain.com.br");
Console.WriteLine("TLD: {0}", domainInfo.Tld); // com.br
Console.WriteLine("Second Level Domain: {0}", domainInfo.Sld); // mydomain
Console.WriteLine("Sub domain: {0}", domainInfo.Subdomain); // h1
Parse throws a FormatException when no TLD rule matches. Use TryParse(string, out DomainInfo) if you'd rather get false.
Extensibility
DomainParserFactory.Create takes three optional arguments. Anything you leave null uses the built-in default.
| Argument | Type | Use it to |
|---|---|---|
configuration |
IConfiguration<Configuration> |
Change TldPublicRulesUrl (default https://publicsuffix.org/list/effective_tld_names.dat) or TldPublicFetchTimeout in ms (default 8000). Empty URL or a timeout below 1 falls back to the default |
customReadOnlyRepositoryExternalPublicList |
IReadOnlyRepository<string, string> |
Load rules from somewhere else (Azure, SQL, a fileβ¦) instead of publicsuffix.org |
loggerFactory |
ILoggerFactory |
Send log output to your Microsoft.Extensions.Logging setup |
A custom rule source, taken from the tests:
var mockRepo = new Mock<IReadOnlyRepository<string, string>>();
mockRepo.Setup(r => r.GetAllAsync(It.IsAny<CancellationToken>()))
.Returns(() => Task.FromResult<IEnumerable<string>>(
new List<string> { "com", "com.br", "co", "io", "uk", "co.uk" }));
var domainParser = DomainParserFactory.Create(null, mockRepo.Object);
Logging
Pass an ILoggerFactory to Create(...) to get debug and error output through Microsoft.Extensions.Logging.
The library also writes to two .NET EventSources, which any EventListener can subscribe to:
| EventSource name | Class |
|---|---|
RSFT-Net-DomainParser-Activity |
Rsft.Net.DomainParser.Diagnostics.EventSources.ActivityLoggingEventSource |
RSFT-Net-DomainParser-Exceptions |
Rsft.Net.DomainParser.Diagnostics.EventSources.ExceptionLoggingEventSource |
Create(...) keeps its state in static fields. Each call rebuilds the parser and replaces the shared logger factory, and the rules cache is a single static MemoryCache. Create the parser once and reuse it.
π Quick start (development)
Prerequisites
- .NET 10 SDK (the test project targets
net10.0) - Internet access to nuget.org and to publicsuffix.org (several tests download the live list)
Build and test
cd src
dotnet build
dotnet test # Debug: runs the tests
Run a single test class:
cd src
dotnet test --filter "FullyQualifiedName~DomainParserFactoryTests"
π§ͺ Testing
xUnit with Moq, in src/Tests/Rsft.Net.DomainParser.Tests.
| Suite | Location | Needs |
|---|---|---|
| Unit | Unit/Repository |
Internet for PublicSuffixRepositoryTests |
| Integration | Integration/ |
Internet for the default factory and live-list tests |
Every test class is wrapped in #if DEBUG. A Release build contains no tests, so dotnet test -c release (what CI runs) reports "No test is available". Run tests in Debug.
ποΈ Project layout
src/
βββ Components/Rsft.Net.DomainParser/
β βββ Data/ Embedded Public Suffix List copy (EffectiveTldNames.txt)
β βββ Diagnostics/ EventSources, event IDs and log messages
β βββ Helpers/ Timeout, safe LINQ and validation helpers
β βββ Logic/ Parser, rules cache, rule resolver, repositories, config
β βββ Service/ Public-facing parser that wraps Logic and maps results
β βββ DomainParserFactory.cs
βββ Tests/Rsft.Net.DomainParser.Tests/ xUnit + Moq tests
βββ Rsft.Net.DomainParser.sln
bitbucket-pipelines.yml
π CI/CD
Bitbucket Pipelines (bitbucket-pipelines.yml), image mcr.microsoft.com/dotnet/sdk:10.0:
- All branches:
dotnet restore, Release build with version${BUILD_VERSION_PREFIX}.${BITBUCKET_BUILD_NUMBER}, thendotnet test -c release. masteronly: the same steps, thendotnet packand publish to NuGet through the sharedemailhippo/nuget-publisherscript.
This README.md is packed into the NuGet package as its readme.
<sub>Β© Email Hippo Ltd</sub>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Jetbrains.Annotations (>= 2026.2.0)
- Microsoft.Extensions.Caching.Memory (>= 11.0.0)
- Microsoft.Extensions.Logging (>= 11.0.0)
- Rsft.Net.DomainParser.Core (>= 1.1.17)
- System.ComponentModel.Annotations (>= 5.0.0)
- System.Diagnostics.Contracts (>= 4.3.0)
- System.Diagnostics.Process (>= 4.3.0)
- System.Diagnostics.TraceSource (>= 4.3.0)
- System.Linq.Queryable (>= 4.3.0)
- System.Reflection (>= 4.3.0)
- System.Runtime.Extensions (>= 4.3.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Rsft.Net.DomainParser:
| Package | Downloads |
|---|---|
|
Utils.Web_Contextual
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.3.241 | 144 | 11/30/2026 |
| 1.3.240 | 99 | 11/29/2026 |
| 1.3.237 | 21,124 | 12/19/2025 |
| 1.3.235 | 648 | 12/9/2025 |
| 1.3.197 | 20,744 | 11/26/2024 |
| 1.3.195 | 55,695 | 10/25/2024 |
| 1.3.193 | 6,478 | 10/9/2024 |
| 1.3.191 | 948 | 9/27/2024 |
| 1.3.189 | 608 | 9/23/2024 |
| 1.3.187 | 1,756 | 9/7/2024 |
| 1.3.185 | 649 | 9/3/2024 |
| 1.3.183 | 976 | 8/21/2024 |
| 1.3.181 | 1,688 | 7/9/2024 |
| 1.3.179 | 418 | 7/7/2024 |
| 1.3.177 | 542 | 6/23/2024 |
| 1.3.175 | 975 | 5/25/2024 |
| 1.3.173 | 437 | 5/23/2024 |
| 1.3.171 | 7,039 | 4/28/2024 |
| 1.3.169 | 614 | 4/12/2024 |
| 1.3.167 | 2,639 | 2/16/2024 |
Split out core as lightweight implementation.