Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 35dd34a

Browse files
committed
Force initializer of MemoryProvider instance
1 parent abbf930 commit 35dd34a

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/ServiceStack.Memory/NetCoreMemory.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ namespace ServiceStack.Memory
1515
{
1616
public sealed class NetCoreMemory : MemoryProvider
1717
{
18-
private NetCoreMemory(){}
19-
public static readonly NetCoreMemory Provider = new NetCoreMemory();
18+
private static NetCoreMemory provider;
19+
public static NetCoreMemory Provider => provider ?? (provider = new NetCoreMemory());
20+
private NetCoreMemory() { }
2021

2122
public static void Configure() => Instance = Provider;
2223

src/ServiceStack.Text/MemoryProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public abstract Task<object> DeserializeAsync(Stream stream, Type type,
7575

7676
public sealed class DefaultMemory : MemoryProvider
7777
{
78-
public static readonly DefaultMemory Provider = new DefaultMemory();
78+
private static DefaultMemory provider;
79+
public static DefaultMemory Provider => provider ?? (provider = new DefaultMemory());
7980
private DefaultMemory() { }
8081

8182
public static void Configure() => Instance = Provider;

src/ServiceStack.Text/NetCoreMemory.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ namespace ServiceStack.Memory
1515
{
1616
public sealed class NetCoreMemory : MemoryProvider
1717
{
18-
private NetCoreMemory(){}
19-
public static readonly NetCoreMemory Provider = new NetCoreMemory();
20-
18+
private static NetCoreMemory provider;
19+
public static NetCoreMemory Provider => provider ?? (provider = new NetCoreMemory());
20+
private NetCoreMemory() { }
21+
2122
public static void Configure() => Instance = Provider;
2223

2324
public override bool ParseBoolean(ReadOnlySpan<char> value) => bool.Parse(value);

0 commit comments

Comments
 (0)