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

Sholtee / injector / 2251

27 Dec 2023 10:00AM UTC coverage: 90.723% (-2.0%) from 92.704%
2251

push

appveyor

Sholtee
Merge branch 'drop_opencover'

2171 of 2393 relevant lines covered (90.72%)

0.91 hits per line

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

91.3
/SRC/Interfaces/Public/Extensions/IServiceCollectionBasicExtensions/Remove.cs
1
/********************************************************************************
2
* Remove.cs                                                                     *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System;
7

8
namespace Solti.Utils.DI.Interfaces
9
{
10
    using Properties;
11

12
    public static partial class IServiceCollectionBasicExtensions
13
    {
14
        /// <summary>
15
        /// Removes the <see cref="AbstractServiceEntry"/> associated with the given <paramref name="type"/> and (optional) <paramref name="key"/>.
16
        /// </summary>
17
        /// <param name="self">The target <see cref="IServiceCollection"/>.</param>
18
        /// <param name="type">The service type.</param>
19
        /// <param name="key">The (optional) service key (usually a name).</param>
20
        /// <exception cref="ServiceNotFoundException">The service could not be found.</exception>
21
        /// <remarks>This method uses linear search so should be avoided in perfomance critical places.</remarks>
22
        public static IServiceCollection Remove(this IServiceCollection self, Type type, object? key)
23
        {
1✔
24
            if (self is null)
1✔
25
                throw new ArgumentNullException(nameof(self));
1✔
26

27
            if (type is null)
1✔
28
                throw new ArgumentNullException(nameof(type));
1✔
29

30
            IServiceId serviceId = new ServiceId(type, key);
1✔
31
            if (!self.Remove(serviceId))
1✔
32
                throw new ServiceNotFoundException
1✔
33
                (
1✔
34
                    string.Format
1✔
35
                    (
1✔
36
                        Resources.Culture,
1✔
37
                        Resources.SERVICE_NOT_FOUND,
1✔
38
                        serviceId
1✔
39
                    ),
1✔
40
                    null,
1✔
41
                    serviceId
1✔
42
                );
1✔
43

44
            return self;
1✔
45
        }
1✔
46

47
        /// <summary>
48
        /// Removes the <see cref="AbstractServiceEntry"/> associated with the given <paramref name="type"/>.
49
        /// </summary>
50
        /// <param name="self">The target <see cref="IServiceCollection"/>.</param>
51
        /// <param name="type">The service type.</param>
52
        /// <exception cref="ServiceNotFoundException">The service could not be found.</exception>
53
        /// <remarks>This method uses linear search so should be avoided in perfomance critical places.</remarks>
54
        public static IServiceCollection Remove(this IServiceCollection self, Type type) => self.Remove(type, null);
×
55

56
        /// <summary>
57
        /// Removes the <see cref="AbstractServiceEntry"/> associated with the given <typeparamref name="TType"/> and (optional) <paramref name="key"/>.
58
        /// </summary>
59
        /// <typeparam name="TType">The service type.</typeparam>
60
        /// <param name="self">The target <see cref="IServiceCollection"/>.</param>
61
        /// <param name="key">The (optional) service key (usually a name).</param>
62
        /// <exception cref="ServiceNotFoundException">The service could not be found.</exception>
63
        /// <remarks>This method uses linear search so should be avoided in perfomance critical places.</remarks>
64
        public static IServiceCollection Remove<TType>(this IServiceCollection self, object? key) where TType : class => self.Remove(typeof(TType), key);
1✔
65

66
        /// <summary>
67
        /// Removes the <see cref="AbstractServiceEntry"/> associated with the given <typeparamref name="TType"/>.
68
        /// </summary>
69
        /// <typeparam name="TType">The service type.</typeparam>
70
        /// <param name="self">The target <see cref="IServiceCollection"/>.</param>
71
        /// <exception cref="ServiceNotFoundException">The service could not be found.</exception>
72
        /// <remarks>This method uses linear search so should be avoided in perfomance critical places.</remarks>
73
        public static IServiceCollection Remove<TType>(this IServiceCollection self) where TType : class => self.Remove(typeof(TType));
×
74
    }
75
}
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

© 2025 Coveralls, Inc