public string GenerateDocumentKey(DocumentConvention conventions, object entity)
{
var tag = conventions.GetTypeTagName(entity.GetType()).ToLowerInvariant();
HiLoKeyGenerator value;
if (keyGeneratorsByTag.TryGetValue(tag, out value))
return value.GenerateDocumentKey(conventions, entity);
lock(generatorLock)
{
if (keyGeneratorsByTag.TryGetValue(tag, out value))
return value.GenerateDocumentKey(conventions, entity);
value = new HiLoKeyGenerator(databaseCommands, tag, capacity);
// doing it this way for thread safety
keyGeneratorsByTag = new Dictionary<string, HiLoKeyGenerator>(keyGeneratorsByTag)
{
{tag, value}
};
}
return value.GenerateDocumentKey(conventions, entity);
}
}