forked from ddrilling/AsbCloudServer
Olga Nemt
b7d1d26722
2. Часть методов перенесены из WellOperationRepository в WellOperationService. 3. Перенастройка ссылок на новый сервис 4. Выделение WellOperationBaseDto
43 lines
1.6 KiB
C#
43 lines
1.6 KiB
C#
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 wellOperationService = serviceProvider.GetRequiredService<IWellOperationService>();
|
||
var wellService = serviceProvider.GetRequiredService<IWellService>();
|
||
|
||
exportServices = new Dictionary<int, Func<IExportService>>
|
||
{
|
||
{
|
||
WellOperation.IdOperationTypeFact,
|
||
() => new WellOperationExport<WellOperationFactTemplate>(wellOperationService, wellService)
|
||
},
|
||
{
|
||
WellOperation.IdOperationTypePlan,
|
||
() => new WellOperationExport<WellOperationPlanTemplate>(wellOperationService, 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), "Не удалось экспортировать файл");
|
||
}
|
||
} |