public Task <string> GenerateDocumentKeyAsync(IAsyncDatabaseCommands databaseCommands, DocumentConvention conventions, object entity)
{
var typeTagName = conventions.GetDynamicTagName(entity);
if (string.IsNullOrEmpty(typeTagName)) //ignore empty tags
{
return(CompletedTask.With <string>(null));
}
var tag = conventions.TransformTypeTagNameToDocumentKeyPrefix(typeTagName);
AsyncHiLoKeyGenerator value;
if (keyGeneratorsByTag.TryGetValue(tag, out value))
{
return(value.GenerateDocumentKeyAsync(databaseCommands, conventions, entity));
}
lock (generatorLock)
{
if (keyGeneratorsByTag.TryGetValue(tag, out value))
{
return(value.GenerateDocumentKeyAsync(databaseCommands, conventions, entity));
}
value = new AsyncHiLoKeyGenerator(tag, capacity);
keyGeneratorsByTag.TryAdd(tag, value);
}
return(value.GenerateDocumentKeyAsync(databaseCommands, conventions, entity));
}