last ...
This commit is contained in:
@@ -1,41 +1,52 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Interfaces;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xDataService.Providers {
|
||||
namespace xDataService.Providers
|
||||
{
|
||||
public class XGuidKeyGenerator<TEntity> : IXKeyGenerator<TEntity, Guid>
|
||||
where TEntity : XBaseEntity<Guid> {
|
||||
private readonly IXSequentialGuid sequentialGuid;
|
||||
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;
|
||||
public XGuidKeyGenerator(
|
||||
IXSequentialGuid sequentialGuid = null
|
||||
)
|
||||
{
|
||||
this.sequentialGuid = sequentialGuid;
|
||||
}
|
||||
|
||||
public async Task<Guid> GenerateKey(
|
||||
IXBaseRepository<TEntity, Guid> repository,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
//
|
||||
// Check if provided SequentialGuid ...
|
||||
if (sequentialGuid.IsNull ()) {
|
||||
return Guid.NewGuid ();
|
||||
} else {
|
||||
return sequentialGuid.Next ();
|
||||
if (sequentialGuid.IsNull())
|
||||
{
|
||||
return Guid.NewGuid();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEmpty (Guid id) {
|
||||
//
|
||||
var result = id.IsNull () || id.IsDefaultGuid ();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return sequentialGuid.Next();
|
||||
}
|
||||
}, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
public bool IsEmpty(Guid id)
|
||||
{
|
||||
//
|
||||
var result = id.IsNull() || id.IsDefaultGuid();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user