Search code examples
c#asp.net.netcastle-windsor

Does using a Castle singleton cause contention in ASP.NET web application


I'm using a readonly dictionary object in a class instantiated with a Singleton lifestyle in an ASP.NET. There's no locking around access to the dictionary object.

Would you expect there to be any .NET contention around reading from this object, given that there may be many web requests accessing it at the same time


Solution

  • This question is actually about dictionary thread-safety, Windsor is unrelated.

    Assuming you're using the standard .NET collections, the MSDN docs for System.Collections.Generic.Dictionary<K,V> say:

    A Dictionary(TKey, TValue) can support multiple readers concurrently, as long as the collection is not modified.

    But it's not thread-safe if you have concurrent writers, which means that it probably doesn't lock anything internally, so I wouldn't expect any contention.