41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using xCommons.Extensions;
|
|
using xDataService.Interfaces;
|
|
using xModels.Base;
|
|
|
|
namespace xDataService.Providers {
|
|
public class XGuidKeyGenerator<TEntity> : IXKeyGenerator<TEntity, Guid>
|
|
where TEntity : XBaseEntity<Guid> {
|
|
private readonly IXSequentialGuid sequentialGuid;
|
|
|
|
public XGuidKeyGenerator (
|
|
IXSequentialGuid sequentialGuid = null
|
|
) {
|
|
this.sequentialGuid = sequentialGuid;
|
|
}
|
|
|
|
public async Task<Guid> GenerateKey (
|
|
IXBaseRepository<TEntity, Guid> repository
|
|
) {
|
|
//
|
|
await Task.CompletedTask;
|
|
|
|
//
|
|
// Check if provided SequentialGuid ...
|
|
if (sequentialGuid.IsNull ()) {
|
|
return Guid.NewGuid ();
|
|
} else {
|
|
return sequentialGuid.Next ();
|
|
}
|
|
}
|
|
|
|
public bool IsEmpty (Guid id) {
|
|
//
|
|
var result = id.IsNull () || id.IsDefaultGuid ();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|
|
} |