Soenneker.Atomics.ValueNullableLazys
4.0.36
Prefix Reserved
dotnet add package Soenneker.Atomics.ValueNullableLazys --version 4.0.36
NuGet\Install-Package Soenneker.Atomics.ValueNullableLazys -Version 4.0.36
<PackageReference Include="Soenneker.Atomics.ValueNullableLazys" Version="4.0.36" />
<PackageVersion Include="Soenneker.Atomics.ValueNullableLazys" Version="4.0.36" />
<PackageReference Include="Soenneker.Atomics.ValueNullableLazys" />
paket add Soenneker.Atomics.ValueNullableLazys --version 4.0.36
#r "nuget: Soenneker.Atomics.ValueNullableLazys, 4.0.36"
#:package Soenneker.Atomics.ValueNullableLazys@4.0.36
#addin nuget:?package=Soenneker.Atomics.ValueNullableLazys&version=4.0.36
#tool nuget:?package=Soenneker.Atomics.ValueNullableLazys&version=4.0.36
Soenneker.Atomics.ValueNullableLazys
Provides inline lazy storage that distinguishes an uninitialized value from a successfully initialized null result.
Install
dotnet add package Soenneker.Atomics.ValueNullableLazys
Usage
Use this variant when null is a valid, cacheable factory result:
using Soenneker.Atomics.ValueLocks;
using Soenneker.Atomics.ValueNullableLazys;
public sealed class UserLookup
{
private ValueAtomicLock _sync;
private ValueNullableLazy<User> _user;
public User? Get(string id) => _user.GetOrCreate(
ref _sync,
id,
static userId => FindUser(userId));
}
After the factory returns—even when it returns null—IsValueCreated is true and later calls reuse that result. TryGetValue distinguishes the states: a false return means uninitialized; a true return with a null output means initialized-to-null.
GetOrCreate runs one factory under the supplied lock and retries after exceptions. GetOrCreatePublicationOnly may run duplicate factories during a race, while GetOrCreateUnsafe requires external synchronization.
Keep both mutable structs in fields. Copies have independent lazy state or lock domains. Publication-only factories should be side-effect free, and losing non-null candidates are not disposed automatically.
What you get
ValueNullableLazy<T>— Provides inline lazy storage that distinguishes an uninitialized value from a successfully initializednullresult.
API at a glance
| API | What it does | Result / important behavior |
|---|---|---|
ValueNullableLazy<T>.IsValueCreated |
Gets a value indicating whether initialization has completed successfully, including when the result was null. | Gets a value indicating whether initialization has completed successfully, including when the result was null. |
ValueNullableLazy<T>.TryGetValue(value) |
Attempts to read the initialized value without invoking a factory. A true return value with a null output means initialization completed with null. | true if the requested update was applied; otherwise, false. |
ValueNullableLazy<T>.GetOrCreate(sync, factory) |
Gets the initialized value or invokes factory exactly once using execution-and-publication semantics. |
The requested value. |
ValueNullableLazy<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. |
ValueNullableLazy<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. |
ValueNullableLazy<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. |
ValueNullableLazy<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 observes the single published result. | The requested value. |
ValueNullableLazy<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
ValueNullableLazy<T>: The default value is ready to use and occupies one reference-sized field. AValueAtomicLockcan be shared by several lazy fields on the same owner, avoiding a separate synchronization object for every value. This is a mutablestructintended 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 | Versions 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. |
-
net10.0
- Soenneker.Atomics.ValueLocks (>= 4.0.23)
-
net9.0
- Soenneker.Atomics.ValueLocks (>= 4.0.23)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Atomics.ValueNullableLazys:
| 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.36 | 3,040 | 10/15/2026 |
| 4.0.35 | 440 | 10/14/2026 |
| 4.0.34 | 2,212 | 10/14/2026 |
| 4.0.33 | 49 | 10/14/2026 |
| 4.0.30 | 3,349 | 10/13/2026 |
| 4.0.27 | 46 | 10/13/2026 |
| 4.0.26 | 85 | 10/12/2026 |
| 4.0.24 | 5,910 | 10/12/2026 |
| 4.0.23 | 4,798 | 10/11/2026 |
| 4.0.22 | 124 | 10/11/2026 |
| 4.0.21 | 125,902 | 9/24/2026 |
| 4.0.20 | 97 | 9/24/2026 |
| 4.0.19 | 37,837 | 9/15/2026 |
| 4.0.18 | 104 | 9/15/2026 |
| 4.0.17 | 107 | 9/15/2026 |
| 4.0.16 | 39,663 | 9/12/2026 |
| 4.0.15 | 356 | 9/12/2026 |
| 4.0.14 | 3,793 | 9/12/2026 |
| 4.0.13 | 4,924 | 9/12/2026 |
| 4.0.12 | 109,536 | 9/2/2026 |
Updated Multiple NuGet packages