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

Sholtee / injector / 2270

06 Dec 2024 06:22AM UTC coverage: 91.153% (+0.4%) from 90.719%
2270

push

appveyor

Sholtee
seems net5.0 is not supported by AppVeyor anymore

1937 of 2125 relevant lines covered (91.15%)

4.52 hits per line

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

85.0
/SRC/Injector/Public/Extensions/IServiceCollectionAdvancedExtensions/ScopeLocal.cs
1
/********************************************************************************
2
* ScopeLocal.cs                                                                 *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System;
7

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

13
    public static partial class IServiceCollectionAdvancedExtensions
14
    {
15
        /// <summary>
16
        /// Registers a slot for a scope-local variable. Scope-locals are instances (for example the HTTP request object) provided by the current session.
17
        /// </summary>
18
        /// <param name="self">The target <see cref="IServiceCollection"/>.</param>
19
        /// <param name="type">The service type to be registered. It can not be null and can be registered only once (with the given <paramref name="key"/>).</param>
20
        /// <param name="key">The (optional) service key (usually a name).</param>
21
        /// <returns></returns>
22
        public static IServiceCollection SetupScopeLocal(this IServiceCollection self, Type type, object? key)
23
        {
5✔
24
            if (self is null)
5✔
25
                throw new ArgumentNullException(nameof(self));
×
26

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

30
            object localKey = new
5✔
31
            {
5✔
32
                __type = type,
5✔
33
                __key = key
5✔
34
            };
5✔
35

36
            return self
5✔
37
                .Service<ScopeLocal>(localKey, Lifetime.Scoped)
5✔
38
                .Factory(type, key, (scope, _) => scope.Get<ScopeLocal>(localKey).Value, Lifetime.Scoped, ServiceOptions.Default with
5✔
39
                {
5✔
40
                    DisposalMode = ServiceDisposalMode.Suppress
5✔
41
                });
5✔
42
        }
5✔
43

44
        /// <summary>
45
        /// Registers a slot for a scope-local variable. Scope-locals are instances (for example the HTTP request object) provided by the current session.
46
        /// </summary>
47
        /// <param name="self">The target <see cref="IServiceCollection"/>.</param>
48
        /// <param name="type">The service type to be registered. It can not be null and can be registered only once.</param>
49
        /// <returns></returns>
50
        public static IServiceCollection SetupScopeLocal(this IServiceCollection self, Type type)
51
            => self.SetupScopeLocal(type, null);
×
52

53
        /// <summary>
54
        /// Registers a slot for a scope-local variable. Scope-locals are instances (for example the HTTP request object) provided by the current session.
55
        /// </summary>
56
        /// <param name="self">The target <see cref="IServiceCollection"/>.</param>
57
        /// <param name="key">The (optional) service key (usually a name).</param>
58
        /// <returns></returns>
59
        public static IServiceCollection SetupScopeLocal<TType>(this IServiceCollection self, object? key)
60
            => self.SetupScopeLocal(typeof(TType), key);
5✔
61

62
        /// <summary>
63
        /// Registers a slot for a scope-local variable. Scope-locals are instances (for example the HTTP request object) provided by the current session.
64
        /// </summary>
65
        /// <param name="self">The target <see cref="IServiceCollection"/>.</param>
66
        /// <returns></returns>
67
        public static IServiceCollection SetupScopeLocal<TType>(this IServiceCollection self)
68
            => self.SetupScopeLocal(typeof(TType), null);
5✔
69
    }
70
}
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