• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

abatar1 / Environment.Setup / 16554220890

27 Jul 2025 06:29PM UTC coverage: 53.279%. Remained the same
16554220890

push

github

abatar1
refactor: rename EnvironmentConfigurationBuilder to EnvironmentConfigurationStatesBuilder and update related usages and documentation

8 of 22 branches covered (36.36%)

Branch coverage included in aggregate %.

6 of 7 new or added lines in 3 files covered. (85.71%)

57 of 100 relevant lines covered (57.0%)

1.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.95
/src/Environment.Setup/ServiceCollectionExtensions.cs
1
using System;
2
using System.Collections.Generic;
3
using Microsoft.Extensions.DependencyInjection;
4

5
namespace Environment.Setup;
6

7
public static class ServiceCollectionExtensions
8
{
9
    /// <summary>
10
    /// Sets up the environment observer by configuring environment-specific state using a provided builder enricher function.
11
    /// </summary>
12
    /// <param name="services">The <see cref="IServiceCollection"/> to which the environment configurations will be added.</param>
13
    /// <param name="builderEnricher">A function that enriches the <see cref="EnvironmentConfigurationStatesBuilder"/> with custom configurations.</param>
14
    /// <returns>The updated <see cref="IServiceCollection"/> containing the configured environment observers.</returns>
15
    public static IServiceCollection SetupEnvironmentObserver(this IServiceCollection services, Func<EnvironmentConfigurationStatesBuilder, EnvironmentConfigurationStatesBuilder> builderEnricher)
16
    {
17
        var builder = new EnvironmentConfigurationStatesBuilder(new Dictionary<Type, EnvironmentConfigurationState>());
1✔
18
        var concreteBuilder = builderEnricher.Invoke(builder);
1✔
19

20
        return RegisterConfigurationsFromStates(services, concreteBuilder.States);
1✔
21
    }
22

23
    /// <summary>
24
    /// Configures the environment observer by applying custom state configurations through a provided builder enricher function.
25
    /// </summary>
26
    /// <param name="services">The <see cref="IServiceCollection"/> instance where the environment configurations will be registered.</param>
27
    /// <param name="builderEnricher">A function that enriches the <see cref="EnvironmentConfigurationStatesBuilder"/> and returns a concrete builder with defined configurations.</param>
28
    /// <returns>The updated <see cref="IServiceCollection"/> including the registered environment configurations.</returns>
29
    internal static IServiceCollection SetupEnvironmentObserver(this IServiceCollection services, Func<EnvironmentConfigurationStatesBuilder, EnvironmentConfigurationConcreteBuilder> builderEnricher)
30
    {
31
        var builder = new EnvironmentConfigurationStatesBuilder(new Dictionary<Type, EnvironmentConfigurationState>());
1✔
32
        var concreteBuilder = builderEnricher.Invoke(builder);
1✔
33
        
34
        return RegisterConfigurationsFromStates(services, concreteBuilder.States);
1✔
35
    }
36

37
    /// <summary>
38
    /// Configures and registers environment-specific settings and observers into the service collection using a custom enricher function
39
    /// that allows interaction with both the configuration builder and the service provider.
40
    /// </summary>
41
    /// <param name="services">The <see cref="IServiceCollection"/> where the environment configurations will be registered.</param>
42
    /// <param name="builderEnricher">A function that customizes the <see cref="EnvironmentConfigurationStatesBuilder"/> by leveraging an
43
    /// instance of <see cref="IServiceProvider"/> for further service dependency access.</param>
44
    /// <returns>The modified <see cref="IServiceCollection"/> containing the registered environment-specific configurations and observers.</returns>
45
    public static IServiceCollection SetupEnvironmentObserver(this IServiceCollection services, Func<EnvironmentConfigurationStatesBuilder, IServiceProvider, EnvironmentConfigurationStatesBuilder> builderEnricher)
46
    {
NEW
47
        var builder = new EnvironmentConfigurationStatesBuilder(new Dictionary<Type, EnvironmentConfigurationState>());
×
48
        var serviceProvider = services.BuildServiceProvider();
×
49
        var concreteBuilder = builderEnricher.Invoke(builder, serviceProvider);
×
50
        
51
        return RegisterConfigurationsFromStates(services, concreteBuilder.States);
×
52
    }
53

54
    private static IServiceCollection RegisterConfigurationsFromStates(IServiceCollection services, Dictionary<Type, EnvironmentConfigurationState> states)
55
    {
56
        foreach (var state in states)
8✔
57
        {
58
            if (state.Value.IsObservable)
2✔
59
                services.AddTransient(state.Key, _ => state.Value.ConfigurationEnricher.Invoke());
3✔
60
            else
61
                services.AddSingleton(state.Key, state.Value.ConfigurationEnricher.Invoke());
1✔
62
        }
63

64
        return services;
2✔
65
    }
66
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc