< Summary - Envilder .NET SDK

Information
Class: Microsoft.Extensions.DependencyInjection.EnvilderServiceCollectionExtensions
Assembly: Envilder
File(s): /home/runner/work/envilder/envilder/src/sdks/dotnet/Infrastructure/DependencyInjection/EnvilderServiceCollectionExtensions.cs
Tag: 352_26963168797
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 46
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddEnvilder(...)100%44100%

File(s)

/home/runner/work/envilder/envilder/src/sdks/dotnet/Infrastructure/DependencyInjection/EnvilderServiceCollectionExtensions.cs

#LineLine coverage
 1namespace Microsoft.Extensions.DependencyInjection;
 2
 3using global::Envilder;
 4using global::Envilder.Infrastructure;
 5using System;
 6using System.IO;
 7
 8/// <summary>
 9/// Extension methods for registering Envilder services in an
 10/// <see cref="IServiceCollection"/> dependency injection container.
 11/// </summary>
 12public static class EnvilderServiceCollectionExtensions
 13{
 14  /// <summary>
 15  /// Parses the map file at <paramref name="mapFilePath"/>, creates an
 16  /// <see cref="EnvilderClient"/> backed by the provider from <c>$config</c>,
 17  /// and registers both the client and the parsed map file as singletons.
 18  /// </summary>
 19  /// <param name="services">The service collection.</param>
 20  /// <param name="mapFilePath">Path to the JSON map file on disk.</param>
 21  /// <param name="options">Optional runtime overrides (provider, profile, vault URL).</param>
 22  /// <returns>The same <see cref="IServiceCollection"/> for chaining.</returns>
 23  public static IServiceCollection AddEnvilder(this IServiceCollection services,
 24                         string mapFilePath,
 25                         EnvilderOptions? options = null)
 26  {
 127    if (string.IsNullOrWhiteSpace(mapFilePath))
 28    {
 129      throw new ArgumentException("Map file path cannot be null or empty.", nameof(mapFilePath));
 30    }
 31
 132    if (!File.Exists(mapFilePath))
 33    {
 134      throw new FileNotFoundException("Map file not found.", mapFilePath);
 35    }
 36
 137    var json = File.ReadAllText(mapFilePath);
 138    var mapFile = new MapFileParser().Parse(json);
 139    var provider = SecretProviderFactory.Create(mapFile.Config, options);
 40
 141    services.AddSingleton(mapFile);
 142    services.AddSingleton(new EnvilderClient(provider));
 43
 144    return services;
 45  }
 46}