Esempio n. 1
0
        private static IServiceReference[] Validate(IInjector injector)
        {
            Config.Value.Injector.StrictDI = false;

            IServiceReference
                svc1, svc2, svc3, svc4;

            svc4 = injector.GetReference(typeof(IInterface_4), null);
            Assert.That(svc4.RefCount, Is.EqualTo(1));
            Assert.That(svc4.Dependencies.Count, Is.EqualTo(3));
            Assert.NotNull(GetDependency(svc4, typeof(IInjector)));
            Assert.NotNull(GetDependency(svc4, typeof(IInterface_2)));
            Assert.NotNull(GetDependency(svc4, typeof(IInterface_3)));

            svc3 = GetDependency(svc4, typeof(IInterface_3));
            Assert.That(svc3.RefCount, Is.EqualTo(2));
            Assert.That(svc3.Dependencies.Count, Is.EqualTo(3));
            Assert.NotNull(GetDependency(svc3, typeof(IInterface_1)));
            Assert.NotNull(GetDependency(svc3, typeof(IInterface_2)));
            Assert.NotNull(GetDependency(svc3, typeof(IReadOnlyDictionary <string, object>), $"{ServiceContainer.INTERNAL_SERVICE_NAME_PREFIX}options")); // implicit fuggoseg

            svc2 = GetDependency(svc4, typeof(IInterface_2));
            Assert.That(svc2.RefCount, Is.EqualTo(3));
            Assert.That(svc2.Dependencies.Count, Is.EqualTo(1));
            Assert.NotNull(GetDependency(svc2, typeof(IInterface_1)));

            svc1 = GetDependency(svc3, typeof(IInterface_1));
            Assert.That(svc1.RefCount, Is.EqualTo(2));
            Assert.That(svc1.Dependencies.Count, Is.EqualTo(1));
            Assert.NotNull(GetDependency(svc1, typeof(IReadOnlyDictionary <string, object>), $"{ServiceContainer.INTERNAL_SERVICE_NAME_PREFIX}options")); // implicit fuggoseg

            return(new[] { svc1, svc2, svc3, svc4 });

            IServiceReference GetDependency(IServiceReference reference, Type iface, string name = null) => reference.Dependencies.SingleOrDefault(dep => dep.RelatedServiceEntry.Interface == iface && dep.RelatedServiceEntry.Name == name);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the dependency graph in <a href="https://graphviz.org/">DOT graph</a> format.
        /// </summary>
        public static string GetDependencyGraph(this IInjector injector, Type serviceInterface, string?serviceName = null)
        {
            if (injector is null)
            {
                throw new ArgumentNullException(nameof(injector));
            }

            return(injector
                   .GetReference(serviceInterface, serviceName)
                   .AsDotGraph()
                   .ToString());
        }