From da1106e77fd7a39eae6cc6cb9249c9e765f6d232 Mon Sep 17 00:00:00 2001 From: Simon Gockner Date: Fri, 22 Nov 2019 16:11:30 +0100 Subject: [PATCH] #30: add `IocContainerException` base exception: - all exceptions inherit this base class - allows handling of exceptions outside of the LightweightIocContainer --- .../Exceptions/CircularDependencyException.cs | 2 +- .../ConstructorNotMatchingException.cs | 2 +- .../IllegalAbstractMethodCreationException.cs | 3 +- .../Exceptions/InternalResolveException.cs | 3 +- .../InvalidRegistrationException.cs | 4 +- .../Exceptions/IocContainerException.cs | 54 +++++++++++++++++++ .../MultipleRegistrationException.cs | 2 +- .../NoMatchingConstructorFoundException.cs | 14 ++--- .../NoPublicConstructorFoundException.cs | 2 +- .../Exceptions/TypeNotRegisteredException.cs | 2 +- .../UnknownRegistrationException.cs | 3 +- .../LightweightIocContainer.xml | 35 +++++++++--- 12 files changed, 96 insertions(+), 30 deletions(-) create mode 100644 LightweightIocContainer/Exceptions/IocContainerException.cs diff --git a/LightweightIocContainer/Exceptions/CircularDependencyException.cs b/LightweightIocContainer/Exceptions/CircularDependencyException.cs index 213d977..9a5de3a 100644 --- a/LightweightIocContainer/Exceptions/CircularDependencyException.cs +++ b/LightweightIocContainer/Exceptions/CircularDependencyException.cs @@ -12,7 +12,7 @@ namespace LightweightIocContainer.Exceptions /// /// A circular dependency was detected during /// - internal class CircularDependencyException : Exception + internal class CircularDependencyException : IocContainerException { /// /// A circular dependency was detected during diff --git a/LightweightIocContainer/Exceptions/ConstructorNotMatchingException.cs b/LightweightIocContainer/Exceptions/ConstructorNotMatchingException.cs index 8d94ae4..0b6c889 100644 --- a/LightweightIocContainer/Exceptions/ConstructorNotMatchingException.cs +++ b/LightweightIocContainer/Exceptions/ConstructorNotMatchingException.cs @@ -10,7 +10,7 @@ namespace LightweightIocContainer.Exceptions /// /// The constructor does not match the given or resolvable arguments /// - internal class ConstructorNotMatchingException : Exception + internal class ConstructorNotMatchingException : IocContainerException { /// /// The constructor does not match the given or resolvable arguments diff --git a/LightweightIocContainer/Exceptions/IllegalAbstractMethodCreationException.cs b/LightweightIocContainer/Exceptions/IllegalAbstractMethodCreationException.cs index 62f050c..8aa95e1 100644 --- a/LightweightIocContainer/Exceptions/IllegalAbstractMethodCreationException.cs +++ b/LightweightIocContainer/Exceptions/IllegalAbstractMethodCreationException.cs @@ -2,7 +2,6 @@ // Created: 2019-06-28 // Copyright(c) 2019 SimonG. All Rights Reserved. -using System; using System.Reflection; namespace LightweightIocContainer.Exceptions @@ -10,7 +9,7 @@ namespace LightweightIocContainer.Exceptions /// /// The creation of the abstract method is illegal in its current state /// - internal class IllegalAbstractMethodCreationException : Exception + internal class IllegalAbstractMethodCreationException : IocContainerException { /// /// The creation of the abstract method is illegal in its current state diff --git a/LightweightIocContainer/Exceptions/InternalResolveException.cs b/LightweightIocContainer/Exceptions/InternalResolveException.cs index 1b9c747..ecfe4e4 100644 --- a/LightweightIocContainer/Exceptions/InternalResolveException.cs +++ b/LightweightIocContainer/Exceptions/InternalResolveException.cs @@ -2,7 +2,6 @@ // Created: 2019-05-27 // Copyright(c) 2019 SimonG. All Rights Reserved. -using System; using LightweightIocContainer.Interfaces; namespace LightweightIocContainer.Exceptions @@ -10,7 +9,7 @@ namespace LightweightIocContainer.Exceptions /// /// An internal Error happened while the tried to resolve an instance /// - internal class InternalResolveException : Exception + internal class InternalResolveException : IocContainerException { /// /// An internal Error happened while the tried to resolve an instance diff --git a/LightweightIocContainer/Exceptions/InvalidRegistrationException.cs b/LightweightIocContainer/Exceptions/InvalidRegistrationException.cs index 5dec77e..11753bc 100644 --- a/LightweightIocContainer/Exceptions/InvalidRegistrationException.cs +++ b/LightweightIocContainer/Exceptions/InvalidRegistrationException.cs @@ -2,14 +2,12 @@ // Created: 2019-05-20 // Copyright(c) 2019 SimonG. All Rights Reserved. -using System; - namespace LightweightIocContainer.Exceptions { /// /// The registration is not valid /// - internal class InvalidRegistrationException : Exception + internal class InvalidRegistrationException : IocContainerException { /// /// The registration is not valid diff --git a/LightweightIocContainer/Exceptions/IocContainerException.cs b/LightweightIocContainer/Exceptions/IocContainerException.cs new file mode 100644 index 0000000..6309d28 --- /dev/null +++ b/LightweightIocContainer/Exceptions/IocContainerException.cs @@ -0,0 +1,54 @@ +// Author: Gockner, Simon +// Created: 2019-11-22 +// Copyright(c) 2019 SimonG. All Rights Reserved. + +using System; +using System.Collections.Generic; +using JetBrains.Annotations; + +namespace LightweightIocContainer.Exceptions +{ + /// + /// A base for the + /// + public abstract class IocContainerException : Exception + { + /// + /// A base for the + /// + protected IocContainerException() + { + + } + + /// + /// A base for the + /// + /// The message of the + protected IocContainerException(string message) + : base(message) + { + + } + + /// + /// A base for the + /// + /// The message of the + /// The inner + protected IocContainerException(string message, Exception innerException) + : base(message, innerException) + { + InnerExceptions = new List() + { + innerException + }; + } + + /// + /// The inner exceptions of the + /// + [UsedImplicitly] + public List InnerExceptions { get; protected set; } + } +} \ No newline at end of file diff --git a/LightweightIocContainer/Exceptions/MultipleRegistrationException.cs b/LightweightIocContainer/Exceptions/MultipleRegistrationException.cs index a2bfb2a..ce7e473 100644 --- a/LightweightIocContainer/Exceptions/MultipleRegistrationException.cs +++ b/LightweightIocContainer/Exceptions/MultipleRegistrationException.cs @@ -10,7 +10,7 @@ namespace LightweightIocContainer.Exceptions /// /// The is already registered in this /// - internal class MultipleRegistrationException : Exception + internal class MultipleRegistrationException : IocContainerException { /// /// The is already registered in this diff --git a/LightweightIocContainer/Exceptions/NoMatchingConstructorFoundException.cs b/LightweightIocContainer/Exceptions/NoMatchingConstructorFoundException.cs index 40bab03..c91391b 100644 --- a/LightweightIocContainer/Exceptions/NoMatchingConstructorFoundException.cs +++ b/LightweightIocContainer/Exceptions/NoMatchingConstructorFoundException.cs @@ -11,7 +11,7 @@ namespace LightweightIocContainer.Exceptions /// /// No matching constructor was found for the given or resolvable arguments /// - internal class NoMatchingConstructorFoundException : AggregateException + internal class NoMatchingConstructorFoundException : IocContainerException { /// /// No matching constructor was found for the given or resolvable arguments @@ -24,9 +24,9 @@ namespace LightweightIocContainer.Exceptions Type = type; if (exceptions == null) - InnerExceptions = new List(); + InnerExceptions = new List(); else - InnerExceptions = exceptions.ToList(); + InnerExceptions = exceptions.OfType().ToList(); } @@ -36,13 +36,7 @@ namespace LightweightIocContainer.Exceptions public Type Type { get; } /// - /// The inner exceptions of the - /// - public new List InnerExceptions { get; } - - - /// - /// Add an inner exception to the + /// Add an inner exception to the /// /// The public void AddInnerException(ConstructorNotMatchingException exception) diff --git a/LightweightIocContainer/Exceptions/NoPublicConstructorFoundException.cs b/LightweightIocContainer/Exceptions/NoPublicConstructorFoundException.cs index 5450f53..79f3dbd 100644 --- a/LightweightIocContainer/Exceptions/NoPublicConstructorFoundException.cs +++ b/LightweightIocContainer/Exceptions/NoPublicConstructorFoundException.cs @@ -9,7 +9,7 @@ namespace LightweightIocContainer.Exceptions /// /// No public constructor can be found for a /// - internal class NoPublicConstructorFoundException : Exception + internal class NoPublicConstructorFoundException : IocContainerException { /// /// No public constructor can be found for a diff --git a/LightweightIocContainer/Exceptions/TypeNotRegisteredException.cs b/LightweightIocContainer/Exceptions/TypeNotRegisteredException.cs index d195309..9b075ad 100644 --- a/LightweightIocContainer/Exceptions/TypeNotRegisteredException.cs +++ b/LightweightIocContainer/Exceptions/TypeNotRegisteredException.cs @@ -10,7 +10,7 @@ namespace LightweightIocContainer.Exceptions /// /// The is not registered in this /// - internal class TypeNotRegisteredException : Exception + internal class TypeNotRegisteredException : IocContainerException { /// /// The is not registered in this diff --git a/LightweightIocContainer/Exceptions/UnknownRegistrationException.cs b/LightweightIocContainer/Exceptions/UnknownRegistrationException.cs index 50b25c2..cc1a290 100644 --- a/LightweightIocContainer/Exceptions/UnknownRegistrationException.cs +++ b/LightweightIocContainer/Exceptions/UnknownRegistrationException.cs @@ -2,7 +2,6 @@ // Created: 2019-05-21 // Copyright(c) 2019 SimonG. All Rights Reserved. -using System; using LightweightIocContainer.Interfaces.Registrations; namespace LightweightIocContainer.Exceptions @@ -10,7 +9,7 @@ namespace LightweightIocContainer.Exceptions /// /// An unknown was used /// - internal class UnknownRegistrationException : Exception + internal class UnknownRegistrationException : IocContainerException { /// /// An unknown was used diff --git a/LightweightIocContainer/LightweightIocContainer.xml b/LightweightIocContainer/LightweightIocContainer.xml index 067c4f7..c200464 100644 --- a/LightweightIocContainer/LightweightIocContainer.xml +++ b/LightweightIocContainer/LightweightIocContainer.xml @@ -127,6 +127,34 @@ The exception message + + + A base for the + + + + + A base for the + + + + + A base for the + + The message of the + + + + A base for the + + The message of the + The inner + + + + The inner exceptions of the + + The is already registered in this @@ -177,14 +205,9 @@ The with no matching constructor - - - The inner exceptions of the - - - Add an inner exception to the + Add an inner exception to the The