Soenneker.AngleSharp.Parser
4.0.59
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.AngleSharp.Parser --version 4.0.59
NuGet\Install-Package Soenneker.AngleSharp.Parser -Version 4.0.59
<PackageReference Include="Soenneker.AngleSharp.Parser" Version="4.0.59" />
<PackageVersion Include="Soenneker.AngleSharp.Parser" Version="4.0.59" />
<PackageReference Include="Soenneker.AngleSharp.Parser" />
paket add Soenneker.AngleSharp.Parser --version 4.0.59
#r "nuget: Soenneker.AngleSharp.Parser, 4.0.59"
#:package Soenneker.AngleSharp.Parser@4.0.59
#addin nuget:?package=Soenneker.AngleSharp.Parser&version=4.0.59
#tool nuget:?package=Soenneker.AngleSharp.Parser&version=4.0.59
Soenneker.AngleSharp.Parser
A DI-friendly cache of configured AngleSharp HtmlParser instances.
Instead of constructing parser configuration throughout an application, request one of three named parser contexts. The service creates each context on first use and returns the cached instance on later calls.
Installation
dotnet add package Soenneker.AngleSharp.Parser
Registration
Use singleton registration when the parser cache should be shared by the application:
using Soenneker.AngleSharp.Parser.Registrars;
builder.Services.AddAngleSharpParserAsSingleton();
Scoped registration creates an independent cache for each dependency-injection scope:
builder.Services.AddAngleSharpParserAsScoped();
Both registrars use TryAdd, so an existing IAngleSharpParser registration is not replaced.
Parse HTML
Inject IAngleSharpParser, retrieve the appropriate configuration, and use the returned AngleSharp parser normally:
using AngleSharp.Dom;
using AngleSharp.Html.Parser;
using Soenneker.AngleSharp.Parser.Abstract;
using Soenneker.AngleSharp.Parser.Enums;
public sealed class PageTitleReader
{
private readonly IAngleSharpParser _parsers;
public PageTitleReader(IAngleSharpParser parsers)
{
_parsers = parsers;
}
public async ValueTask<string?> Read(
string html,
CancellationToken cancellationToken)
{
HtmlParser parser = await _parsers.Get(
AngleSharpContextType.Fast,
cancellationToken);
using IDocument document = await parser.ParseDocumentAsync(
html,
cancellationToken);
return document.QuerySelector("title")?.TextContent.Trim();
}
}
Get() without a context argument is equivalent to Get(AngleSharpContextType.Default).
Parser contexts
| Context | Configuration | Use it for |
|---|---|---|
Default |
AngleSharp's default HtmlParser configuration. |
General HTML parsing when no specialized behavior is needed. |
Fast |
Scripting disabled and no resource loader added. | Parsing supplied HTML for scraping, normalization, or querying without external resource loading. |
WithLoader |
Scripting enabled and AngleSharp's default loader configured with resource loading enabled. | Workflows that need a loader-enabled browsing context. |
Choose the context deliberately. WithLoader permits resource loading through its browsing context, so do not use it with untrusted input in environments where outbound requests must be restricted.
Cache and lifetime behavior
The cache is keyed by AngleSharpContextType. Within one IAngleSharpParser service instance:
- the first request for a context creates its
HtmlParser; - subsequent requests for that context return the same parser instance;
- requests for different contexts return independently configured instances;
- concurrent cache initialization is coordinated by the underlying singleton-key dictionary.
The thread-safety guarantee applies to creating and retrieving cached entries. Because callers receive the same mutable HtmlParser object for a context, avoid changing its configuration after retrieval and validate concurrent parsing behavior against the AngleSharp version used by your application.
The service implements both IDisposable and IAsyncDisposable. Let the dependency-injection container dispose registered instances. If you construct AngleSharpParser yourself, dispose that service when its cache is no longer needed.
API
| Method | Purpose |
|---|---|
Get(CancellationToken) |
Returns the cached Default parser. |
Get(AngleSharpContextType, CancellationToken) |
Returns the cached parser for the selected context. |
AddAngleSharpParserAsSingleton() |
Registers one application-wide parser cache. |
AddAngleSharpParserAsScoped() |
Registers one parser cache per DI scope. |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- AngleSharp (>= 1.7.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.11)
- Soenneker.Dictionaries.SingletonKeys (>= 4.0.125)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Soenneker.AngleSharp.Parser:
| Package | Downloads |
|---|---|
|
Soenneker.Html.Parser
A utility library for HTML parsing related operations |
|
|
Soenneker.Extensions.String.Html
A collection of helpful html string extension methods |
|
|
Soenneker.Html.Formatter
A utility library that formats and normalizes HTML strings and files. |
|
|
Soenneker.Html.Normalizer
Deterministic, configurable HTML normalization for hashing and change detection. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.60 | 0 | 8/30/2026 |
| 4.0.59 | 0 | 8/30/2026 |
| 4.0.58 | 0 | 8/29/2026 |
| 4.0.57 | 28 | 8/29/2026 |
| 4.0.56 | 27 | 8/29/2026 |
| 4.0.55 | 28 | 8/29/2026 |
| 4.0.54 | 324 | 8/26/2026 |
| 4.0.53 | 175 | 8/26/2026 |
| 4.0.52 | 304 | 8/24/2026 |
| 4.0.51 | 403 | 8/21/2026 |
| 4.0.50 | 469 | 8/18/2026 |
| 4.0.49 | 527 | 8/12/2026 |
| 4.0.48 | 119 | 8/12/2026 |
| 4.0.47 | 578 | 8/9/2026 |
| 4.0.46 | 310 | 8/8/2026 |
| 4.0.45 | 623 | 8/7/2026 |
| 4.0.44 | 187 | 8/6/2026 |
| 4.0.43 | 246 | 8/1/2026 |
| 4.0.42 | 417 | 7/29/2026 |
| 4.0.41 | 477 | 7/29/2026 |