RegisterUnique

This commit is contained in:
Stephan
2018-11-29 10:35:16 +01:00
parent e9de6c1fc9
commit c6891c6c70
63 changed files with 520 additions and 602 deletions

View File

@@ -1,71 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Umbraco.Core.Exceptions
{
/// <summary>
/// Represents errors that occur due to LightInject.
/// </summary>
public class LightInjectException : Exception
{
public LightInjectException(string message)
: base(message)
{ }
public LightInjectException(string message, Exception innerException)
: base(message, innerException)
{ }
private const string LightInjectUnableToResolveType = "Unable to resolve type:";
private const string LightInjectUnresolvedDependency = "Unresolved dependency ";
private const string LightInjectRequestedDependency = "[Requested dependency:";
public static void TryThrow(Exception e)
{
var ex = e as InvalidOperationException;
if (ex == null || ex.Message.StartsWith(LightInjectUnableToResolveType) == false)
return;
var sb = new StringBuilder();
sb.AppendLine("Unresolved type: " + ex.Message.Substring(LightInjectUnableToResolveType.Length));
WriteDetails(ex, sb);
throw new LightInjectException(sb.ToString(), e);
}
public static void TryThrow(Exception e, Type implementingType)
{
var ex = e as InvalidOperationException;
if (ex == null || ex.Message.StartsWith(LightInjectUnableToResolveType) == false)
return;
var sb = new StringBuilder();
sb.AppendLine("Unresolved type: " + ex.Message.Substring(LightInjectUnableToResolveType.Length));
sb.AppendLine("Implementing type: " + implementingType);
WriteDetails(ex, sb);
throw new LightInjectException(sb.ToString(), e);
}
private static void WriteDetails(InvalidOperationException ex, StringBuilder sb)
{
ex = ex.InnerException as InvalidOperationException;
while (ex != null)
{
var message = ex.Message;
if (message.StartsWith(LightInjectUnableToResolveType))
{
sb.AppendLine("-> Unresolved type: " + message.Substring(LightInjectUnableToResolveType.Length));
}
else if (message.StartsWith(LightInjectUnresolvedDependency))
{
var pos = message.InvariantIndexOf(LightInjectRequestedDependency);
sb.AppendLine("-> Unresolved dependency: " + message.Substring(pos + LightInjectRequestedDependency.Length + 1).TrimEnd(']'));
}
ex = ex.InnerException as InvalidOperationException;
}
}
}
}