refactor dbcontext lifetime (#258)
* refactor create playout handler * refactor get all playouts handler * refactor delete playout handler * remove dead code * ignore unnamed artists for collections * more repository cleanup * more schedule items refactoring * more playout refactoring * refactor playout builder * refactor ffmpeg profiles * more ffmpeg profile refactoring * rework resolutions * refactor media collections * refactor config elements * update changelog * more cleanup
This commit is contained in:
@@ -1,23 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ErsatzTV.Core.Interfaces.Repositories;
|
||||
using ErsatzTV.Infrastructure.Data;
|
||||
using MediatR;
|
||||
using static ErsatzTV.Application.ProgramSchedules.Mapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ErsatzTV.Application.ProgramSchedules.Queries
|
||||
{
|
||||
public class GetAllProgramSchedulesHandler : IRequestHandler<GetAllProgramSchedules, List<ProgramScheduleViewModel>>
|
||||
{
|
||||
private readonly IProgramScheduleRepository _programScheduleRepository;
|
||||
private readonly IDbContextFactory<TvContext> _dbContextFactory;
|
||||
|
||||
public GetAllProgramSchedulesHandler(IProgramScheduleRepository programScheduleRepository) =>
|
||||
_programScheduleRepository = programScheduleRepository;
|
||||
public GetAllProgramSchedulesHandler(IDbContextFactory<TvContext> dbContextFactory) =>
|
||||
_dbContextFactory = dbContextFactory;
|
||||
|
||||
public async Task<List<ProgramScheduleViewModel>> Handle(
|
||||
GetAllProgramSchedules request,
|
||||
CancellationToken cancellationToken) =>
|
||||
(await _programScheduleRepository.GetAll()).Map(ProjectToViewModel).ToList();
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
await using TvContext dbContext = _dbContextFactory.CreateDbContext();
|
||||
return await dbContext.ProgramSchedules
|
||||
.Map(
|
||||
ps => new ProgramScheduleViewModel(
|
||||
ps.Id,
|
||||
ps.Name,
|
||||
ps.MediaCollectionPlaybackOrder,
|
||||
ps.KeepMultiPartEpisodesTogether,
|
||||
ps.TreatCollectionsAsShows))
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user