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

futurum-dev / dotnet.futurum.microsoft.extensions.dependencyinjection / 7282541346

21 Dec 2023 12:50AM UTC coverage: 77.064% (-12.0%) from 89.063%
7282541346

Pull #23

github

web-flow
Merge cb0ebf1e7 into 313efb734
Pull Request #23: Adding 'Keyed' service registration

9 of 20 branches covered (0.0%)

Branch coverage included in aggregate %.

22 of 36 new or added lines in 1 file covered. (61.11%)

75 of 89 relevant lines covered (84.27%)

2.24 hits per line

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

51.92
/src/Futurum.Microsoft.Extensions.DependencyInjection/ServiceCollectionDescriptorExtensions.cs
1
using Microsoft.Extensions.DependencyInjection;
2

3
namespace Futurum.Microsoft.Extensions.DependencyInjection;
4

5
public static class ServiceCollectionDescriptorExtensions
6
{
7
    public static void TryAddEquatableKeyedScoped(this IServiceCollection collection, Type service, object? serviceKey, Type implementationType)
8
    {
2✔
9
        var descriptor = ServiceDescriptor.KeyedScoped(service, serviceKey, implementationType);
2✔
10
        collection.TryAddEquatableKeyed(descriptor);
2✔
11
    }
2✔
12

13
    public static void TryAddEquatableKeyedSingleton(this IServiceCollection collection, Type service, object? serviceKey, Type implementationType)
14
    {
2✔
15
        var descriptor = ServiceDescriptor.KeyedSingleton(service, serviceKey, implementationType);
2✔
16
        collection.TryAddEquatableKeyed(descriptor);
2✔
17
    }
2✔
18

19
    public static void TryAddEquatableKeyedTransient(this IServiceCollection collection, Type service, object? serviceKey, Type implementationType)
20
    {
2✔
21
        var descriptor = ServiceDescriptor.KeyedTransient(service, serviceKey, implementationType);
2✔
22
        collection.TryAddEquatableKeyed(descriptor);
2✔
23
    }
2✔
24

25
    public static IServiceCollection TryAddEquatableKeyed(this IServiceCollection collection, ServiceDescriptor descriptor)
26
    {
6✔
27
        var count = collection.Count;
6✔
28
        for (var index = 0; index < count; ++index)
12✔
29
        {
3✔
30
            var serviceKey = collection[index].ServiceKey;
3✔
31
            if (serviceKey != null && collection[index].ServiceType == descriptor.ServiceType && serviceKey.Equals(descriptor.ServiceKey))
3!
32
                return collection;
3✔
NEW
33
        }
×
34

35
        collection.Add(descriptor);
3✔
36

37
        return collection;
3✔
38
    }
6✔
39

40
    public static IServiceCollection ReplaceEquatableKeyed(this IServiceCollection collection, ServiceDescriptor descriptor)
NEW
41
    {
×
NEW
42
        var count = collection.Count;
×
NEW
43
        for (var index = 0; index < count; ++index)
×
NEW
44
        {
×
NEW
45
            var serviceKey = collection[index].ServiceKey;
×
NEW
46
            if (serviceKey != null && collection[index].ServiceType == descriptor.ServiceType && serviceKey.Equals(descriptor.ServiceKey))
×
NEW
47
            {
×
NEW
48
                collection.RemoveAt(index);
×
NEW
49
                break;
×
50
            }
NEW
51
        }
×
52

NEW
53
        collection.Add(descriptor);
×
54

NEW
55
        return collection;
×
NEW
56
    }
×
57
}
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