Soenneker.AngleSharp.Parser 4.0.59

Prefix Reserved
There is a newer version of this package available.
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
                    
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="Soenneker.AngleSharp.Parser" Version="4.0.59" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.AngleSharp.Parser" Version="4.0.59" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.AngleSharp.Parser" />
                    
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 Soenneker.AngleSharp.Parser --version 4.0.59
                    
#r "nuget: Soenneker.AngleSharp.Parser, 4.0.59"
                    
#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 Soenneker.AngleSharp.Parser@4.0.59
                    
#: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=Soenneker.AngleSharp.Parser&version=4.0.59
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.AngleSharp.Parser&version=4.0.59
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

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

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