namespace Adapters.Driven.Persistence.DataLoaders; using Adapters.Driven.Persistence.Context; using Domain.Entities; using GreenDonut; using Microsoft.EntityFrameworkCore; public class ProfessorByIdDataLoader : BatchDataLoader { private readonly IDbContextFactory _contextFactory; public ProfessorByIdDataLoader( IDbContextFactory contextFactory, IBatchScheduler batchScheduler, DataLoaderOptions? options = null) : base(batchScheduler, options ?? new DataLoaderOptions()) { _contextFactory = contextFactory; } protected override async Task> LoadBatchAsync( IReadOnlyList keys, CancellationToken ct) { await using var context = await _contextFactory.CreateDbContextAsync(ct); return await context.Professors .Where(p => keys.Contains(p.Id)) .ToDictionaryAsync(p => p.Id, ct); } }