namespace Unosquare.Swan.Exceptions
{
using System;
using System.Collections.Generic;
using System.Linq;
///
/// Generic Constraint Registration Exception.
///
///
public class DependencyContainerRegistrationException : Exception
{
private const string ConvertErrorText = "Cannot convert current registration of {0} to {1}";
private const string RegisterErrorText =
"Cannot register type {0} - abstract classes or interfaces are not valid implementation types for {1}.";
private const string ErrorText = "Duplicate implementation of type {0} found ({1}).";
///
/// Initializes a new instance of the class.
///
/// Type of the register.
/// The types.
public DependencyContainerRegistrationException(Type registerType, IEnumerable types)
: base(string.Format(ErrorText, registerType, GetTypesString(types)))
{
}
///
/// Initializes a new instance of the class.
///
/// The type.
/// The method.
/// if set to true [is type factory].
public DependencyContainerRegistrationException(Type type, string method, bool isTypeFactory = false)
: base(isTypeFactory
? string.Format(RegisterErrorText, type.FullName, method)
: string.Format(ConvertErrorText, type.FullName, method))
{
}
private static string GetTypesString(IEnumerable types)
{
return string.Join(",", types.Select(type => type.FullName));
}
}
}