Make pipeline deep immutable #285

Open
opened 2026-01-29 14:32:47 +00:00 by claunia · 1 comment
Owner

Originally created by @xoofx on GitHub (Apr 5, 2019).

Today, options pushed from a user to parsers but also directly parser instance (which are less directly exposed to users) can be modified during the process of request.

The work on making the markdown pipeline thread/safe immutable was only valid for the list part of the extensions ( #5 ), but is not really valid for some classes that are shared and can be modified during the process of a pipeline.

We need to figure out what we want to do with that.

Likely, we will have to make all these classes immutable - which will require painful constructors...etc.

(See for example comment on PR 327 )

Originally created by @xoofx on GitHub (Apr 5, 2019). Today, options pushed from a user to parsers but also directly parser instance (which are less directly exposed to users) can be modified during the process of request. The work on making the markdown pipeline thread/safe immutable was only valid for the list part of the extensions ( #5 ), but is not really valid for some classes that are shared and can be modified during the process of a pipeline. We need to figure out what we want to do with that. Likely, we will have to make all these classes immutable - which will require painful constructors...etc. (See for example [comment on PR 327](https://github.com/lunet-io/markdig/pull/327#pullrequestreview-223355552) )
claunia added the enhancement label 2026-01-29 14:32:47 +00:00
Author
Owner

@MihaZupan commented on GitHub (Apr 5, 2019):

An internal Clone() method could be added to *Option classes.

For the cases where properties are not collections (only bools, strings), it could be simply implemented as

internal AutoLinkOptions Clone() => MemberwiseClone() as AutoLinkOptions;

And then have that be used by the extension like

private readonly AutoLinkOptions _options;

public AutoLinkExtension(AutoLinkOptions options)
{
    _options = options?.Clone() ?? new AutoLinkOptions();
}
@MihaZupan commented on GitHub (Apr 5, 2019): An internal `Clone()` method could be added to `*Option` classes. For the cases where properties are not collections (only bools, strings), it could be simply implemented as ```csharp internal AutoLinkOptions Clone() => MemberwiseClone() as AutoLinkOptions; ``` And then have that be used by the extension like ```csharp private readonly AutoLinkOptions _options; public AutoLinkExtension(AutoLinkOptions options) { _options = options?.Clone() ?? new AutoLinkOptions(); } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#285