< Summary

Information
Class: Chronicis.Client.Extensions.ServiceCollectionExtensions
Assembly: Chronicis.Client
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Client/Extensions/ServiceCollectionExtensions.cs
Line coverage
100%
Covered lines: 24
Uncovered lines: 0
Coverable lines: 24
Total lines: 97
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
AddChronicisApiService(...)100%11100%
AddChronicisApiServiceWithSnackbar(...)100%11100%
AddChronicisApiServiceWithJSRuntime(...)100%11100%
AddChronicisApiServiceConcrete(...)100%11100%

File(s)

/home/runner/work/chronicis/chronicis/src/Chronicis.Client/Extensions/ServiceCollectionExtensions.cs

#LineLine coverage
 1namespace Chronicis.Client.Extensions;
 2
 3/// <summary>
 4/// Extension methods for IServiceCollection to simplify API service registrations.
 5/// </summary>
 6public static class ServiceCollectionExtensions
 7{
 8    /// <summary>
 9    /// Registers a Chronicis API service with the standard dependencies (HttpClient via factory, ILogger).
 10    /// </summary>
 11    /// <typeparam name="TInterface">The service interface type.</typeparam>
 12    /// <typeparam name="TImplementation">The service implementation type.</typeparam>
 13    /// <param name="services">The service collection.</param>
 14    /// <param name="httpClientName">The name of the configured HTTP client (default: "ChronicisApi").</param>
 15    /// <returns>The service collection for chaining.</returns>
 16    public static IServiceCollection AddChronicisApiService<TInterface, TImplementation>(
 17        this IServiceCollection services,
 18        string httpClientName = "ChronicisApi")
 19        where TInterface : class
 20        where TImplementation : class, TInterface
 21    {
 1822        services.AddScoped<TInterface>(sp =>
 1823        {
 1824            var httpClient = sp.GetRequiredService<IHttpClientFactory>().CreateClient(httpClientName);
 1825            return ActivatorUtilities.CreateInstance<TImplementation>(sp, httpClient);
 1826        });
 27
 1828        return services;
 29    }
 30
 31    /// <summary>
 32    /// Registers a Chronicis API service with additional ISnackbar dependency.
 33    /// </summary>
 34    /// <typeparam name="TInterface">The service interface type.</typeparam>
 35    /// <typeparam name="TImplementation">The service implementation type.</typeparam>
 36    /// <param name="services">The service collection.</param>
 37    /// <param name="httpClientName">The name of the configured HTTP client (default: "ChronicisApi").</param>
 38    /// <returns>The service collection for chaining.</returns>
 39    public static IServiceCollection AddChronicisApiServiceWithSnackbar<TInterface, TImplementation>(
 40        this IServiceCollection services,
 41        string httpClientName = "ChronicisApi")
 42        where TInterface : class
 43        where TImplementation : class, TInterface
 44    {
 245        services.AddScoped<TInterface>(sp =>
 246        {
 247            var httpClient = sp.GetRequiredService<IHttpClientFactory>().CreateClient(httpClientName);
 248            return ActivatorUtilities.CreateInstance<TImplementation>(sp, httpClient);
 249        });
 50
 251        return services;
 52    }
 53
 54    /// <summary>
 55    /// Registers a Chronicis API service with additional IJSRuntime dependency.
 56    /// </summary>
 57    /// <typeparam name="TInterface">The service interface type.</typeparam>
 58    /// <typeparam name="TImplementation">The service implementation type.</typeparam>
 59    /// <param name="services">The service collection.</param>
 60    /// <param name="httpClientName">The name of the configured HTTP client (default: "ChronicisApi").</param>
 61    /// <returns>The service collection for chaining.</returns>
 62    public static IServiceCollection AddChronicisApiServiceWithJSRuntime<TInterface, TImplementation>(
 63        this IServiceCollection services,
 64        string httpClientName = "ChronicisApi")
 65        where TInterface : class
 66        where TImplementation : class, TInterface
 67    {
 268        services.AddScoped<TInterface>(sp =>
 269        {
 270            var httpClient = sp.GetRequiredService<IHttpClientFactory>().CreateClient(httpClientName);
 271            return ActivatorUtilities.CreateInstance<TImplementation>(sp, httpClient);
 272        });
 73
 274        return services;
 75    }
 76
 77    /// <summary>
 78    /// Registers a concrete Chronicis API service (no interface).
 79    /// </summary>
 80    /// <typeparam name="TImplementation">The service implementation type.</typeparam>
 81    /// <param name="services">The service collection.</param>
 82    /// <param name="httpClientName">The name of the configured HTTP client (default: "ChronicisApi").</param>
 83    /// <returns>The service collection for chaining.</returns>
 84    public static IServiceCollection AddChronicisApiServiceConcrete<TImplementation>(
 85        this IServiceCollection services,
 86        string httpClientName = "ChronicisApi")
 87        where TImplementation : class
 88    {
 189        services.AddScoped<TImplementation>(sp =>
 190        {
 191            var httpClient = sp.GetRequiredService<IHttpClientFactory>().CreateClient(httpClientName);
 192            return ActivatorUtilities.CreateInstance<TImplementation>(sp, httpClient);
 193        });
 94
 195        return services;
 96    }
 97}