Description
SqlMapper.SetTypeMap is thread safe. This is achievede by:
lock (_typeMaps)
{
...
}
But SqlMapper.AddTypeHandler is not thread safe.
I think it would be valuable to make AddTypehandler thread safe as it enables different data access to be self contained instead of having a central place for registering all custom types.
Scenario:
Using 3rd party package A and another third party package B.
These both use Dapper. No problem, it is the same version.
These two packages each register some custom type handlers lazily, the first time they need them.
In AddTypeHandler there is no locking, the flow is as follows:
...
var snapshot = typeHandlers;
... // <= In this time span, multiple simultanious calls will trigger lost updates.
typeHandlers = newCopy;
I felt this the hard way in production yesterday.
Activity