Soenneker.Atomics.ValueLazys 4.0.11

Prefix Reserved
dotnet add package Soenneker.Atomics.ValueLazys --version 4.0.11
                    
NuGet\Install-Package Soenneker.Atomics.ValueLazys -Version 4.0.11
                    
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.Atomics.ValueLazys" Version="4.0.11" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Atomics.ValueLazys" Version="4.0.11" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Atomics.ValueLazys" />
                    
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.Atomics.ValueLazys --version 4.0.11
                    
#r "nuget: Soenneker.Atomics.ValueLazys, 4.0.11"
                    
#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.Atomics.ValueLazys@4.0.11
                    
#: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.Atomics.ValueLazys&version=4.0.11
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Atomics.ValueLazys&version=4.0.11
                    
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.Atomics.ValueLazys

Provides inline lazy storage for a non-null reference value without allocating a Lazy{T} wrapper.

Install

dotnet add package Soenneker.Atomics.ValueLazys

Usage

Store both mutable structs as fields and pass the lock by reference:

using System.Text.RegularExpressions;
using Soenneker.Atomics.ValueLazys;
using Soenneker.Atomics.ValueLocks;

public sealed class InputValidator
{
    private ValueAtomicLock _sync;
    private ValueLazy<Regex> _pattern;

    public Regex Pattern => _pattern.GetOrCreate(
        ref _sync,
        static () => new Regex("^[a-z0-9-]+$"));
}

GetOrCreate provides execution-and-publication: one caller runs the factory while competitors wait on the supplied lock. Exceptions are not cached, so a later call retries.

GetOrCreatePublicationOnly avoids the lock but may run the factory concurrently several times; only one non-null reference wins publication. Use it only when duplicate construction is safe and abandoned candidates need no disposal. GetOrCreateUnsafe requires external synchronization or single-threaded access.

Do not copy ValueLazy<T> or the accompanying ValueAtomicLock. Copies establish independent storage or lock domains and defeat initialization coordination.

What you get

  • ValueLazy<T> — Provides inline lazy storage for a non-null reference value without allocating a Lazy{T} wrapper.

API at a glance

API What it does Result / important behavior
ValueLazy<T>.IsValueCreated Gets a value indicating whether initialization has completed successfully. Gets a value indicating whether initialization has completed successfully.
ValueLazy<T>.TryGetValue(value) Attempts to read the initialized value without invoking a factory. true if the requested update was applied; otherwise, false.
ValueLazy<T>.GetOrCreate(sync, factory) Gets the initialized value or invokes factory exactly once using execution-and-publication semantics. The requested value.
ValueLazy<T>.GetOrCreate(sync, state, factory) Gets the initialized value or invokes factory exactly once using execution-and-publication semantics. Supplying state allows callers to use a static factory and avoid a closure allocation. The requested value.
ValueLazy<T>.GetOrCreateUnsafe(factory) Gets or creates the value without locking. This method is only safe when the caller provides external synchronization or guarantees single-threaded access. The requested value.
ValueLazy<T>.GetOrCreateUnsafe(state, factory) Gets or creates the value without locking. Supplying state allows callers to use a static factory and avoid a closure allocation. The requested value.
ValueLazy<T>.GetOrCreatePublicationOnly(factory) Gets the initialized value or atomically publishes one factory result. During a race the factory may run more than once, but every caller receives the single published value. The requested value.
ValueLazy<T>.GetOrCreatePublicationOnly(state, factory) Gets the initialized value or atomically publishes one factory result. Supplying state allows callers to use a static factory and avoid a closure allocation. The requested value.

Important behavior

  • ValueLazy<T>: The default value is ready to use and occupies one reference-sized field. A ValueAtomicLock can be shared by several lazy fields on the same owner, avoiding a separate synchronization object for every value. This is a mutable struct intended for use as a private field. Avoid copying it because each copy has independent initialization state. Exceptions thrown by a factory are not cached, and a later call may retry initialization.
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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 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 (1)

Showing the top 1 NuGet packages that depend on Soenneker.Atomics.ValueLazys:

Package Downloads
Soenneker.Reflection.Cache

The fastest .NET Reflection cache

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.11 0 9/3/2026
4.0.9 34 9/2/2026
4.0.8 1,006 9/2/2026
4.0.7 1,949 9/1/2026
4.0.6 8,069 8/31/2026
4.0.5 14,790 8/29/2026
4.0.4 77 8/29/2026
4.0.3 72 8/29/2026
4.0.2 47,383 8/27/2026
4.0.1 165 8/26/2026