< Summary

Information
Class: MyNet.UI.Notifications.ServiceCollectionExtensions
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/Notifications/Extensions/ServiceCollectionExtensions.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 7
Uncovered lines: 0
Coverable lines: 7
Total lines: 44
Line coverage: 100%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddNotifications(...)50%22100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/Notifications/Extensions/ServiceCollectionExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="ServiceCollectionExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Collections.Generic;
 9using Microsoft.Extensions.DependencyInjection;
 10using Microsoft.Extensions.DependencyInjection.Extensions;
 11using MyNet.UI.Notifications.Processors;
 12using MyNet.UI.Threading;
 13
 14#pragma warning disable IDE0130
 15namespace MyNet.UI.Notifications;
 16#pragma warning restore IDE0130
 17
 18/// <summary>
 19/// Extension methods for registering notification services.
 20/// </summary>
 21public static class ServiceCollectionExtensions
 22{
 23    /// <summary>
 24    /// Registers the built-in notification service and manager.
 25    /// </summary>
 26    /// <param name="services">Service collection.</param>
 27    /// <param name="configureProcessors">Optional callback to add processors applied before publication.</param>
 28    /// <returns>The same service collection for chaining.</returns>
 29    public static IServiceCollection AddNotifications(
 30        this IServiceCollection services,
 31        Action<IList<INotificationProcessor>>? configureProcessors = null)
 32    {
 1233        var processors = new List<INotificationProcessor>();
 1234        configureProcessors?.Invoke(processors);
 35
 1236        services.AddSchedulerProvider();
 1237        services.TryAddSingleton<INotificationService>(_ => new NotificationService(processors));
 1238        services.TryAddSingleton<INotificationPublisher>(x => x.GetRequiredService<INotificationService>());
 1239        services.TryAddSingleton<INotificationsManager, NotificationsManager>();
 40
 1241        return services;
 42    }
 43}
 44