C# ASP.NET Thread Safe static read only field C# ASP.NET Thread Safe static read only field asp.net asp.net

C# ASP.NET Thread Safe static read only field


Initialization of static fields is thread-safe: that is, the .NET runtime guarantees that your field will be initialized only once in the program, no matter how many threads access it and in what order.

As Andrey points out, the Service.Get method itself needs to be thread-safe.


IoC itself looks ok, but the whole structure will not be thread-safe if resolver is not thread safe. If you want to have resolver per thread you can use attribute [ThreadStatic]