< Summary

Information
Class: NostrSure.Infrastructure.Client.ServiceCollectionExtensions
Assembly: NostrSure.Infrastructure
File(s): /home/runner/work/NostrSure/NostrSure/NostrSure.Infrastructure/Client/ServiceCollectionExtensions.cs
Line coverage
100%
Covered lines: 31
Uncovered lines: 0
Coverable lines: 31
Total lines: 75
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
AddNostrClient(...)100%11100%
AddNostrClient(...)100%11100%

File(s)

/home/runner/work/NostrSure/NostrSure/NostrSure.Infrastructure/Client/ServiceCollectionExtensions.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2using Microsoft.Extensions.ObjectPool;
 3using NostrSure.Infrastructure.Client.Abstractions;
 4using NostrSure.Infrastructure.Client.Implementation;
 5using System.Text;
 6
 7namespace NostrSure.Infrastructure.Client;
 8
 9/// <summary>
 10/// Extension methods for configuring Nostr client services
 11/// </summary>
 12public static class ServiceCollectionExtensions
 13{
 14    /// <summary>
 15    /// Adds all Nostr client services to the DI container using refactored WebSocket implementation
 16    /// </summary>
 17    public static IServiceCollection AddNostrClient(this IServiceCollection services)
 318    {
 19        // Object pooling for performance
 320        services.AddSingleton<ObjectPool<StringBuilder>>(provider =>
 221        {
 222            var objectPoolProvider = new DefaultObjectPoolProvider();
 223            var policy = new StringBuilderPooledObjectPolicy();
 224            return objectPoolProvider.Create(policy);
 525        });
 26
 27        // Refactored WebSocket components
 328        services.AddSingleton<IWebSocketFactory, WebSocketFactory>();
 29
 30        // Core services
 331        services.AddSingleton<IMessageSerializer, JsonMessageSerializer>();
 332        services.AddSingleton<ISubscriptionManager, InMemorySubscriptionManager>();
 333        services.AddSingleton<IEventDispatcher, DefaultEventDispatcher>();
 334        services.AddSingleton<IHealthPolicy, RetryBackoffPolicy>();
 35
 36        // Main client
 337        services.AddTransient<INostrClient, NostrClient>();
 38
 339        return services;
 340    }
 41
 42    /// <summary>
 43    /// Adds Nostr client services with custom health policy configuration
 44    /// </summary>
 45    public static IServiceCollection AddNostrClient(this IServiceCollection services,
 46                                                   TimeSpan? baseDelay = null,
 47                                                   TimeSpan? maxDelay = null,
 48                                                   int maxRetries = 5)
 249    {
 50        // Object pooling for performance
 251        services.AddSingleton<ObjectPool<StringBuilder>>(provider =>
 252        {
 253            var objectPoolProvider = new DefaultObjectPoolProvider();
 254            var policy = new StringBuilderPooledObjectPolicy();
 255            return objectPoolProvider.Create(policy);
 456        });
 57
 58        // Refactored WebSocket components
 259        services.AddSingleton<IWebSocketFactory, WebSocketFactory>();
 60
 61        // Core services
 262        services.AddSingleton<IMessageSerializer, JsonMessageSerializer>();
 263        services.AddSingleton<ISubscriptionManager, InMemorySubscriptionManager>();
 264        services.AddSingleton<IEventDispatcher, DefaultEventDispatcher>();
 65
 66        // Custom health policy
 267        services.AddSingleton<IHealthPolicy>(provider =>
 468            new RetryBackoffPolicy(baseDelay, maxDelay, maxRetries));
 69
 70        // Main client
 271        services.AddTransient<INostrClient, NostrClient>();
 72
 273        return services;
 274    }
 75}