Initial Commit ...
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user