• 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

65.79
/SRC/Injector/Private/ServiceErrors.cs
1
/********************************************************************************
2
* ServiceErrors.cs                                                              *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System;
7
using System.Diagnostics;
8
using System.Runtime.CompilerServices;
9

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

14
    using static Properties.Resources;
15

16
    //
17
    // This class is to use the same validation logic in JIT and AOT resolutins too
18
    //
19

20
    internal static class ServiceErrors
21
    {
22
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
23
        public static void NotFound(Type type, object? key, AbstractServiceEntry? requestor)
24
        {
1✔
25
            ServiceId requested = new(type, key);
1✔
26
            throw new ServiceNotFoundException
1✔
27
            (
1✔
28
                string.Format(Culture, SERVICE_NOT_FOUND, requested.ToString()),
1✔
29
                requestor,
1✔
30
                requested
1✔
31
            );
1✔
32
        }
33

34
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
35
        public static void EnsureNotBreaksTheRuleOfStrictDI(AbstractServiceEntry requestor, AbstractServiceEntry requested, bool supportServiceProvider)
36
        {
1✔
37
            if ((requested.Type == typeof(IInjector) || (supportServiceProvider && requested.Type == typeof(IServiceProvider))) && requested.Key is null)
1✔
38
            {
1✔
39
                RequestNotAllowedException ex = new(STRICT_DI_SCOPE);
1✔
40
                try
41
                {
1✔
42
                    ex.Data[nameof(requestor)] = requestor;
1✔
43
                    ex.Data[nameof(requested)] = requested;
1✔
44
                }
1✔
45
                catch (ArgumentException)
×
46
                {
×
47
                    //
48
                    // .NET FW throws if value assigned to Exception.Data is not serializable
49
                    //
50

51
                    Debug.Assert(Environment.Version.Major == 4, "Only .NET FW should complain about serialization");
×
52

53
                    ex.Data[nameof(requestor)] = requestor.ToString(shortForm: false);
×
54
                    ex.Data[nameof(requested)] = requested.ToString(shortForm: false);
×
55
                }
×
56

57
                throw ex;
1✔
58
            }
59

60
            //
61
            // The requested service should not exist longer than its requestor.
62
            //
63

64
            if (requested.Lifetime?.CompareTo(requestor.Lifetime!) < 0)
×
65
            {
1✔
66
                RequestNotAllowedException ex = new(STRICT_DI_DEP);
1✔
67
                try
68
                {
1✔
69
                    ex.Data[nameof(requestor)] = requestor;
1✔
70
                    ex.Data[nameof(requested)] = requested;
1✔
71
                }
1✔
72
                catch (ArgumentException)
×
73
                {
×
74
                    //
75
                    // .NET FW throws if value assigned to Exception.Data is not serializable
76
                    //
77

78
                    Debug.Assert(Environment.Version.Major == 4, "Only .NET FW should complain about serialization");
×
79

80
                    ex.Data[nameof(requestor)] = requestor.ToString(shortForm: false);
×
81
                    ex.Data[nameof(requested)] = requested.ToString(shortForm: false);
×
82
                }
×
83
                throw ex;
1✔
84
            }
85
        }
1✔
86
    }
87
}
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