• 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

95.0
/SRC/Injector/Private/Expressions/DependencyResolvers/RegularDependencyResolver.cs
1
/********************************************************************************
2
* RegularDependencyResolver.cs                                                  *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System.Linq.Expressions;
7
using System.Reflection;
8

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

14
    internal sealed class RegularDependencyResolver: IDependencyResolver
15
    {
16
        private static readonly MethodInfo
1✔
17
            FInjectorGet = MethodInfoExtractor.Extract<IInjector>(static i => i.Get(null!, null)),
1✔
18
            FInjectorTryGet = MethodInfoExtractor.Extract<IInjector>(static i => i.TryGet(null!, null));
1✔
19

20
        public object Id { get; } = nameof(RegularDependencyResolver);
1✔
21

22
        /// <summary>
23
        /// <code>(TInterface) injector.[Try]Get(typeof(TInterface), options?.Name)</code>
24
        /// </summary>
25
        public Expression Resolve(ParameterExpression injector, DependencyDescriptor dependency, object? userData, object? context, CallNextDelegate<object?, Expression> next)
26
        {
1✔
27
            if (dependency.Type.IsClass || dependency.Type.IsInterface)
1✔
28
            {
1✔
29
                return Expression.Convert
1✔
30
                (
1✔
31
                    Expression.Call
1✔
32
                    (
1✔
33
                        injector,
1✔
34
                        dependency.Options?.Optional is true ? FInjectorTryGet : FInjectorGet,
1✔
35
                        Expression.Constant(dependency.Type),
1✔
36
                        Expression.Constant(dependency.Options?.Key, typeof(string))
1✔
37
                    ),
1✔
38
                    dependency.Type
1✔
39
                );
1✔
40
            }
41
            return next(context);
×
42
        }
1✔
43
    }
44
}
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