public ServiceInstallerOptions AddInstaller(IServiceInstaller installer)
        {
            if (_installers.All(o => o.GetType() != installer.GetType()))
            {
                _installers.Add(installer);
            }

            return(this);
        }
Esempio n. 2
0
            /// <summary>
            /// Initializes a new instance of the <see cref="Node"/> class.
            /// </summary>
            /// <param name="installer">Associated service installer.</param>
            /// <exception cref="System.ArgumentNullException">
            /// If <paramref name="installer"/> is <c>null</c>.
            /// </exception>
            public Node(IServiceInstaller installer)
            {
                if (installer == null)
                {
                    throw new ArgumentNullException("installer");
                }

                this.Installer = installer;
                this.Inputs    = new HashSet <Node>();
                this.Targets   = new HashSet <Node>();
            }
Esempio n. 3
0
        public RunnerBuilder UseInstaller(IServiceInstaller installer)
        {
            var key = installer.GetType().FullName;

            if (!installers.ContainsKey(key))
            {
                installers.Add(key, installer);
            }

            return(this);
        }
            /// <summary>
            /// Generate error message which highlights services with circular dependencies.
            /// </summary>
            /// <remarks>
            /// <para>You can check the value of <see cref="HasCircularDependency"/> to
            /// determine whether circular dependencies hvae been detected before using
            /// this method.</para>
            /// </remarks>
            /// <param name="contextInstaller">Circular dependencies are reported if related
            /// to the specified context service installer.</param>
            /// <returns>
            /// A string containing an error message when circular service dependencies
            /// have been detected; otherwise, a value of <c>null</c>.
            /// </returns>
            /// <exception cref="System.ArgumentNullException">
            /// If <paramref name="contextInstaller"/> is a value of <c>null</c>.
            /// </exception>
            /// <seealso cref="HasCircularDependency"/>
            public string GenerateCircularDependencyErrorMessage(IServiceInstaller contextInstaller)
            {
                if (contextInstaller == null)
                {
                    throw new ArgumentNullException("contextInstaller");
                }

                var circularNode = CircularDependencyNodes.FirstOrDefault(n => n.Installer == contextInstaller);

                if (circularNode != null)
                {
                    // Produce list of other services that form circular dependency.
                    var circular = new HashSet <ServiceDependencyGraph.Node>();
                    AddCircularDependencies(circularNode, circular);
                    circular.Remove(circularNode);

                    var sb = new StringBuilder();
                    sb.AppendLine(circular.Count > 1 ? "Has Circular Dependencies:" : "Has Circular Dependency:");
                    sb.AppendLine();

                    // Present immediate dependencies first.
                    foreach (var n in circularNode.Targets)
                    {
                        sb.AppendLine("  ➜ " + n.Installer.TargetService.ServiceType.FullName);
                        circular.Remove(n);
                    }

                    // Then present subsequent dependencies.
                    foreach (var n in circular)
                    {
                        sb.AppendLine("  → " + n.Installer.TargetService.ServiceType.FullName);
                    }

                    return(sb.ToString());
                }
                else
                {
                    return(null);
                }
            }