DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/WellOperations/Factories/WellOperationExportServiceFactory.cs

43 lines
1.5 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests.ExportOptions;
using AsbCloudApp.Services;
using AsbCloudApp.Services.Export;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.WellOperations;
using Microsoft.Extensions.DependencyInjection;
namespace AsbCloudInfrastructure.Services.WellOperations.Factories;
public class WellOperationExportServiceFactory : IExportServiceFactory<int>
{
private readonly IDictionary<int, Func<IExportService>> exportServices;
public WellOperationExportServiceFactory(IServiceProvider serviceProvider)
{
var wellOperationRepository = serviceProvider.GetRequiredService<IWellOperationRepository>();
var wellService = serviceProvider.GetRequiredService<IWellService>();
exportServices = new Dictionary<int, Func<IExportService>>
{
{
WellOperation.IdOperationTypeFact,
() => new WellOperationExport<WellOperationFactTemplate>(wellOperationRepository, wellService)
},
{
WellOperation.IdOperationTypePlan,
() => new WellOperationExport<WellOperationPlanTemplate>(wellOperationRepository, wellService)
}
};
}
public IExportService<TOptions> CreateExportService<TOptions>(int id)
where TOptions : IExportOptionsRequest
{
var parser = exportServices[id].Invoke();
return parser as IExportService<TOptions>
?? throw new ArgumentNullException(nameof(id), "Не удалось экспортировать файл");
}
}