| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="ServiceCollectionExtensions.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using Microsoft.Extensions.DependencyInjection; |
| | | 9 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 10 | | using MyNet.UI.Notifications; |
| | | 11 | | using MyNet.UI.Threading; |
| | | 12 | | using MyNet.UI.Toasting.Filters; |
| | | 13 | | using MyNet.UI.Toasting.Settings; |
| | | 14 | | |
| | | 15 | | #pragma warning disable IDE0130 |
| | | 16 | | namespace MyNet.UI.Toasting; |
| | | 17 | | #pragma warning restore IDE0130 |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Extension methods for registering toast services. |
| | | 21 | | /// </summary> |
| | | 22 | | public static class ServiceCollectionExtensions |
| | | 23 | | { |
| | | 24 | | /// <summary> |
| | | 25 | | /// Registers toast services with default implementations. |
| | | 26 | | /// </summary> |
| | | 27 | | /// <param name="services">Service collection.</param> |
| | | 28 | | /// <param name="configureOptions">Optional callback used to customize toast manager options.</param> |
| | | 29 | | /// <returns>The same service collection for chaining.</returns> |
| | | 30 | | public static IServiceCollection AddToasting( |
| | | 31 | | this IServiceCollection services, |
| | | 32 | | Action<ToastManagerOptions>? configureOptions = null) |
| | | 33 | | { |
| | 12 | 34 | | var options = new ToastManagerOptions(); |
| | 12 | 35 | | configureOptions?.Invoke(options); |
| | | 36 | | |
| | 12 | 37 | | services.AddSchedulerProvider(); |
| | 12 | 38 | | services.TryAddSingleton<INotificationService>(_ => new NotificationService([])); |
| | 12 | 39 | | services.TryAddSingleton<IToastFilter, AllToastsFilter>(); |
| | 12 | 40 | | services.TryAddSingleton<IToastFactory, DefaultToastFactory>(); |
| | 12 | 41 | | services.TryAddSingleton(options); |
| | 12 | 42 | | services.TryAddSingleton<IToastManager, ToastManager>(); |
| | | 43 | | |
| | 12 | 44 | | return services; |
| | | 45 | | } |
| | | 46 | | } |
| | | 47 | | |