| | | 1 | | using ArturRios.Data.Export.Abstractions; |
| | | 2 | | using ArturRios.Data.Export.Configuration; |
| | | 3 | | using ArturRios.Data.Export.Exporters; |
| | | 4 | | using Microsoft.Extensions.DependencyInjection; |
| | | 5 | | |
| | | 6 | | namespace ArturRios.Data.Export.DependencyInjection; |
| | | 7 | | |
| | | 8 | | /// <summary>Dependency-injection registration for the ArturRios.Data.Export core exporters.</summary> |
| | | 9 | | public static class ServiceCollectionExtensions |
| | | 10 | | { |
| | | 11 | | /// <param name="services">The service collection.</param> |
| | | 12 | | extension(IServiceCollection services) |
| | | 13 | | { |
| | | 14 | | /// <summary>Registers the exporter factory and the CSV/JSON/TXT/MessagePack exporters.</summary> |
| | | 15 | | /// <param name="configure">Optional options configuration.</param> |
| | | 16 | | public IServiceCollection AddExport(Action<ExportOptions>? configure = null) |
| | 8 | 17 | | { |
| | 8 | 18 | | var options = new ExportOptions(); |
| | 8 | 19 | | configure?.Invoke(options); |
| | | 20 | | |
| | 8 | 21 | | services.AddSingleton(options.Csv); |
| | 8 | 22 | | services.AddSingleton(options.Json); |
| | 8 | 23 | | services.AddSingleton(options.Txt); |
| | 8 | 24 | | services.AddSingleton(options.MessagePack); |
| | | 25 | | |
| | 8 | 26 | | services.AddSingleton(typeof(CsvExporter<>)); |
| | 8 | 27 | | services.AddSingleton(typeof(JsonExporter<>)); |
| | 8 | 28 | | services.AddSingleton(typeof(TxtExporter<>)); |
| | 8 | 29 | | services.AddSingleton(typeof(MessagePackExporter<>)); |
| | | 30 | | |
| | 8 | 31 | | services.AddSingleton<IExporterFactory, ExporterFactory>(); |
| | | 32 | | |
| | 8 | 33 | | return services; |
| | | 34 | | } |
| | | 35 | | } |
| | | 36 | | } |