/src/LinFu.IoC/Configuration/RecursiveDependencyException.cs
http://github.com/philiplaureano/LinFu · C# · 56 lines · 33 code · 7 blank · 16 comment · 4 complexity · 6fa2af1a912b3fceca6ebe1992726ccc MD5 · raw file
- using System;
- using System.Collections.Generic;
- using System.Text;
- using LinFu.IoC.Interfaces;
- namespace LinFu.IoC.Configuration
- {
- /// <summary>
- /// The exception thrown when a recursive dependency is detected
- /// inside a <see cref="IServiceContainer" /> instance.
- /// </summary>
- [Serializable]
- public class RecursiveDependencyException : Exception
- {
- private readonly LinkedList<Type> _typeChain;
- /// <summary>
- /// Initializes the <see cref="RecursiveDependencyException" />
- /// class with the <paramref name="typeChain">chain</paramref>
- /// of depedencies that caused the exception.
- /// </summary>
- /// <param name="typeChain">The sequence of types that caused the dependency exception.</param>
- public RecursiveDependencyException(LinkedList<Type> typeChain)
- {
- _typeChain = typeChain;
- }
- /// <summary>
- /// Gets the value indicating the chain of types that caused the exception.
- /// </summary>
- public LinkedList<Type> TypeChain => new LinkedList<Type>(_typeChain);
- /// <summary>
- /// Gets the value indicating the error message from the <see cref="RecursiveDependencyException" />.
- /// </summary>
- public override string Message
- {
- get
- {
- var messageFormat = "Recursive Dependency Detected: {0}";
- var builder = new StringBuilder();
- var currentNode = _typeChain.First;
- while (currentNode != null)
- {
- builder.AppendFormat("{0}", currentNode.Value.AssemblyQualifiedName);
- if (currentNode.Next != null) builder.Append("--->");
- currentNode = currentNode.Next;
- }
- return string.Format(messageFormat, builder);
- }
- }
- }
- }