fix GraphQL DI Registration Using Generics ...
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Extensions;
|
||||
using xDataService.Interfaces;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xDataService.Providers
|
||||
{
|
||||
/// <summary>
|
||||
/// Default Long Key Generator ...
|
||||
/// </summary>
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
public class XLongKeyGenerator<TEntity> : XKeyGenerator<TEntity, long>, IXKeyGenerator<TEntity, long>
|
||||
where TEntity : XBaseEntity<long>
|
||||
{
|
||||
public override async Task<long> GenerateKey(
|
||||
IXBaseRepository<TEntity, long> repository,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var items = (await repository.GetAllAsync())
|
||||
.OrderByDescending(nameof(XBaseEntity<long>.Id));
|
||||
var last = items
|
||||
.FirstOrDefault();
|
||||
|
||||
//
|
||||
var result = last.IsNull() ? 1 : last.Id + 1;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool IsEmpty(long id)
|
||||
{
|
||||
//
|
||||
var result = id <= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user