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

43 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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), "Не удалось экспортировать файл");
}
}