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

🌐 Components · Domain Parser

.NET library that splits a domain name into TLD, second-level domain (SLD) and subdomain using the Public Suffix List.

.NET Standard NuGet License


✨ 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 MemoryCache for 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:

  1. All branches: dotnet restore, Release build with version ${BUILD_VERSION_PREFIX}.${BITBUCKET_BUILD_NUMBER}, then dotnet test -c release.
  2. master only: the same steps, then dotnet pack and publish to NuGet through the shared emailhippo/nuget-publisher script.

This README.md is packed into the NuGet package as its readme.


<sub>Β© Email Hippo Ltd</sub>

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed

Split out core as lightweight implementation.