Skip to content

Commit aa5e01e

Browse files
Merge pull request #1659 from microsoft/mk/reader-concurrent-dictionary
Fixes concurrent error with registry
2 parents 5015239 + 15ce520 commit aa5e01e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Microsoft.OpenApi/Reader/OpenApiReaderRegistry.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33

44
using System;
5+
using System.Collections.Concurrent;
56
using System.Collections.Generic;
67
using Microsoft.OpenApi.Interfaces;
78

@@ -12,7 +13,7 @@ namespace Microsoft.OpenApi.Reader
1213
/// </summary>
1314
public static class OpenApiReaderRegistry
1415
{
15-
private static readonly Dictionary<string, IOpenApiReader> _readers = new(StringComparer.OrdinalIgnoreCase);
16+
private static readonly ConcurrentDictionary<string, IOpenApiReader> _readers = new(StringComparer.OrdinalIgnoreCase);
1617

1718
/// <summary>
1819
/// Defines a default OpenAPI reader.
@@ -26,7 +27,7 @@ public static class OpenApiReaderRegistry
2627
/// <param name="reader">The reader instance.</param>
2728
public static void RegisterReader(string format, IOpenApiReader reader)
2829
{
29-
_readers[format] = reader;
30+
_readers.AddOrUpdate(format, reader, (_, _) => reader);
3031
}
3132

3233
/// <summary>

0 commit comments

Comments
 (0)