Use ConcurrentDictionary instead of Dictionary in Catalog?
Closed this issue · 2 comments
The Translation
in Catalog.cs
is Dictionary<string, string[]>
, can we use ConcurrentDicitionary
instead in order to make it thread safe to get translation?
NGettext/src/NGettext/Catalog.cs
Line 32 in d83be9b
NGettext/src/NGettext/Catalog.cs
Lines 336 to 341 in d83be9b
In the current implementation Catalog is thread safe if you don't modify the Translations
dictionary manually but use the loader in the constructor (and also you should use the ICatalog
interface everywhere as it only exposes the translation methods).
Read operations of Dictionary are thread safe unless you concurrently write into it.
I understand that exposing a non thread safe property makes the current implementation unsafe, it has been done to keep backwards compatibility with older versions of the library and in version 1.0 I'm planning to implement the loaders properly without exposing internal stuff.
Thanks for your clarification. I noticed that some targeted frameworks don't support ConcurrentDictionary
so I can understand why not simply change it.
And I agreed with that ILoader
implementation needs to rewrite in order to avoid exposing Translations
.
Issue closed.