49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using xCommons.Extensions;
|
|
using xDataService.Interfaces;
|
|
using xModels.Base;
|
|
|
|
namespace xDataService.Providers
|
|
{
|
|
/// <summary>
|
|
/// Default Guid Key Generator ...
|
|
/// </summary>
|
|
/// <typeparam name="TEntity"></typeparam>
|
|
|
|
public class XStringKeyGenerator<TEntity> : XKeyGenerator<TEntity, string>, IXKeyGenerator<TEntity, string>
|
|
where TEntity : XBaseEntity<string>
|
|
{
|
|
private readonly IXSequentialGuid sequentialGuid;
|
|
|
|
public XStringKeyGenerator(IXSequentialGuid sequentialGuid = null)
|
|
{
|
|
this.sequentialGuid = sequentialGuid;
|
|
}
|
|
|
|
public override async Task<string> GenerateKey(
|
|
IXBaseRepository<TEntity, string> repository,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
await Task.CompletedTask;
|
|
|
|
//
|
|
if (sequentialGuid.IsNull())
|
|
{
|
|
return Guid.NewGuid().ToString();
|
|
}
|
|
else
|
|
{
|
|
return sequentialGuid.Next().ToString();
|
|
}
|
|
}
|
|
|
|
public override bool IsEmpty(string id)
|
|
{
|
|
return id.IsNullOrEmpty();
|
|
}
|
|
}
|
|
} |