| | | 1 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 2 | | using Microsoft.Extensions.Options; |
| | | 3 | | using ZhEaIsNsAaBn.Utilities.PrintPDF; |
| | | 4 | | |
| | | 5 | | // ReSharper disable once CheckNamespace |
| | | 6 | | namespace Microsoft.Extensions.DependencyInjection; |
| | | 7 | | |
| | | 8 | | /// <summary>Registers PDF printing.</summary> |
| | | 9 | | public static class PrintPdfRegistration |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Registers <see cref="ChromiumHandler"/> as a singleton (one browser for the app, closed when the container is di |
| | | 13 | | /// with <see cref="ChromiumOptions"/> as <c>IOptions</c>. |
| | | 14 | | /// </summary> |
| | | 15 | | /// <param name="services">The service collection.</param> |
| | | 16 | | /// <param name="configure">Options, e.g. <c>o => o.ExecutablePath = "/usr/bin/chromium"</c>; <see langword="null |
| | | 17 | | /// <returns>The service collection.</returns> |
| | | 18 | | /// <exception cref="ArgumentNullException"><paramref name="services"/> is <see langword="null"/>.</exception> |
| | | 19 | | public static IServiceCollection AddPrintPdf( this IServiceCollection services, Action<ChromiumOptions>? configure = |
| | | 20 | | { |
| | 4 | 21 | | ArgumentNullException.ThrowIfNull( services ); |
| | | 22 | | |
| | 4 | 23 | | var options = services.AddOptions<ChromiumOptions>(); |
| | | 24 | | |
| | 6 | 25 | | if ( configure is not null ) { options.Configure( configure ); } |
| | | 26 | | |
| | | 27 | | |
| | 4 | 28 | | services.TryAddSingleton( sp => new ChromiumHandler( sp.GetRequiredService<IOptions<ChromiumOptions>>().Value ) |
| | | 29 | | |
| | 4 | 30 | | return services; |
| | | 31 | | } |
| | | 32 | | } |