< Summary

Information
Class: MyNet.Text.GeneratorServiceCollectionExtensions
Assembly: MyNet.Text
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Text/Extensions/GeneratorServiceCollectionExtensions.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 37
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddRandomGenerator(...)100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Text/Extensions/GeneratorServiceCollectionExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="GeneratorServiceCollectionExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using Microsoft.Extensions.DependencyInjection;
 8using Microsoft.Extensions.DependencyInjection.Extensions;
 9using MyNet.Generator;
 10using MyNet.Generator.Facade;
 11using MyNet.Text.Randomize;
 12
 13#pragma warning disable IDE0130 // Namespace does not match folder structure
 14namespace MyNet.Text;
 15#pragma warning restore IDE0130 // Namespace does not match folder structure
 16
 17public static class GeneratorServiceCollectionExtensions
 18{
 19    /// <summary>
 20    /// Registers random generator services in DI and aligns static facades with the same singleton instance.
 21    /// </summary>
 22    public static IServiceCollection AddRandomGenerator(this IServiceCollection services)
 23    {
 424        services.TryAddSingleton<IRandomSource, SystemRandomSource>();
 425        services.TryAddSingleton<IRandomGenerator, DefaultRandomGenerator>();
 426        services.TryAddSingleton<ITextRandomGenerator>(TextRandomGenerator.Current);
 27
 428        services.TryAddSingleton(provider =>
 429        {
 430            RandomGenerator.Current = provider.GetRequiredService<IRandomGenerator>();
 431            return RandomGenerator.Current;
 432        });
 33
 434        return services;
 35    }
 36}
 37