< Summary - Envilder .NET SDK

Information
Class: Envilder.Infrastructure.DependencyInjection.ServiceCollectionExtensions
Assembly: Envilder
File(s): /home/runner/work/envilder/envilder/src/sdks/dotnet/Infrastructure/DependencyInjection/ServiceCollectionExtensions.cs
Tag: 299_25910610327
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 47
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/ServiceCollectionExtensions.cs

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