28 lines
1.0 KiB
C#
28 lines
1.0 KiB
C#
using Application.Interfaces.Services;
|
|
using Domain.Entities;
|
|
using GreenDonut.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace GraphQLTEST.GraphQL.DataLoaders;
|
|
|
|
public class KillsByUserDataLoader : GroupedDataLoader<int, Kill>{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
public KillsByUserDataLoader(
|
|
IServiceProvider serviceProvider,
|
|
IBatchScheduler batchScheduler,
|
|
DataLoaderOptions options): base(batchScheduler, options){
|
|
_serviceProvider = serviceProvider;
|
|
}
|
|
|
|
protected override async Task<ILookup<int, Kill>> LoadGroupedBatchAsync(IReadOnlyList<int> keys, CancellationToken cancellationToken)
|
|
{
|
|
await using var scope = _serviceProvider.CreateAsyncScope();
|
|
var service = scope.ServiceProvider.GetRequiredService<IKillService>();
|
|
|
|
return await service.GetKillsByUserId(keys)
|
|
.ToAsyncEnumerable()
|
|
.ToLookupAsync(k => k.UserId, cancellationToken: cancellationToken);
|
|
}
|
|
} |