• 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

94.83
/SRC/Injector/Private/ServiceEntryBuilders/DotGraphBuilder.cs
1
/********************************************************************************
2
* DotGraphBuilder.cs                                                            *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System;
7
using System.Collections.Generic;
8
using System.Linq;
9
using System.Linq.Expressions;
10

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

15
    internal sealed class DotGraphBuilder: IServiceEntryBuilder
16
    {
17
        private readonly ServicePath FPath = new();
1✔
18

19
        private readonly IServiceResolver FResolver;
20

21
        public DotGraph Graph { get; } = new();
1✔
22

23
        public DotGraphBuilder(IServiceResolver resolver)
1✔
24
        {
1✔
25
            Visitors = new IFactoryVisitor[]
1✔
26
            {
1✔
27
                new MergeProxiesVisitor(),
1✔
28
                new DotGraphBuilderVisitor(this)
1✔
29
            };
1✔
30
            FResolver = resolver;
1✔
31
        }
1✔
32

33
        public IReadOnlyList<IFactoryVisitor> Visitors { get; }
1✔
34

35
        public IBuildContext BuildContext { get; } = null!;
×
36

37
        public void Build(Type type, object? key) => Build
1✔
38
        (
1✔
39
            FResolver.Resolve(type, key) ?? new MissingServiceEntry(type, key)
1✔
40
        );
1✔
41

42
        public void Build(AbstractServiceEntry entry)
43
        {
1✔
44
            ServiceNode child = new(entry);
1✔
45

46
            if (FPath.Last is not null)
1✔
47
            {
1✔
48
                Graph.Edges.Add
1✔
49
                (
1✔
50
                    new ServiceEdge
1✔
51
                    (
1✔
52
                        new ServiceNode(FPath.Last),
1✔
53
                        child
1✔
54
                    )
1✔
55
                );
1✔
56
            }
1✔
57

58
            Graph.Nodes.Add(child);
1✔
59

60
            if (!entry.Features.HasFlag(ServiceEntryFeatures.SupportsBuild))
1✔
61
                return;
1✔
62

63
            try
64
            {
1✔
65
                FPath.Push(entry);
1✔
66
            }
1✔
67
            catch (CircularReferenceException cref)
1✔
68
            {
1✔
69
                foreach (ServiceEdge edge in Graph.Edges)
1✔
70
                {
1✔
71
                    if (cref.Circle.Contains(edge.From.RelatedEntry) && cref.Circle.Contains(edge.To.RelatedEntry))
×
72
                    {
1✔
73
                        edge.MarkRed();
1✔
74
                    }
1✔
75
                }
1✔
76
                return;
1✔
77
            }
78

79
            try
80
            {
1✔
81
                Visitors.Aggregate<IFactoryVisitor, LambdaExpression>
1✔
82
                (
1✔
83
                    entry.Factory!,
1✔
84
                    (visited, visitor) => visitor.Visit(visited, entry)
1✔
85
                );
1✔
86
            }
1✔
87
            finally
88
            {
1✔
89
                FPath.Pop();
1✔
90
            }
1✔
91
        }
1✔
92

93
        public void Init(IEnumerable<AbstractServiceEntry> entries) { }
×
94
    }
95
}
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