Skip to content

Commit fddfb48

Browse files
committed
1 parent 5d7616e commit fddfb48

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

src/Dependency/Injection/Parameters/OptionalGenericParameter.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System;
2-
using Unity.Policy;
2+
using Unity.Exceptions;
33
using Unity.Resolution;
44

55
namespace Unity.Injection
@@ -42,7 +42,11 @@ protected override ResolveDelegate<TContext> GetResolver<TContext>(Type type, st
4242
return (ref TContext context) =>
4343
{
4444
try { return context.Resolve(type, name); }
45-
catch {return null; }
45+
catch (Exception ex)
46+
when (!(ex.InnerException is CircularDependencyException))
47+
{
48+
return null;
49+
}
4650
};
4751
}
4852

src/Dependency/Injection/Parameters/OptionalParameter.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22
using System.Reflection;
3-
using Unity.Policy;
3+
using Unity.Exceptions;
44
using Unity.Resolution;
55

66
namespace Unity.Injection
@@ -75,7 +75,11 @@ public ResolveDelegate<TContext> GetResolver<TContext>(Type type)
7575
return (ref TContext c) =>
7676
{
7777
try { return c.Resolve(type, _name); }
78-
catch { return null; }
78+
catch (Exception ex)
79+
when (!(ex.InnerException is CircularDependencyException))
80+
{
81+
return null;
82+
}
7983
};
8084
}
8185

@@ -102,14 +106,22 @@ public ResolveDelegate<TContext> GetResolver<TContext>(ParameterInfo info)
102106
return (ref TContext c) =>
103107
{
104108
try { return c.Resolve(type, _name); }
105-
catch { return value; }
109+
catch (Exception ex)
110+
when (!(ex.InnerException is CircularDependencyException))
111+
{
112+
return value;
113+
}
106114
};
107115
}
108116

109117
return (ref TContext c) =>
110118
{
111119
try { return c.Resolve(ParameterType, _name); }
112-
catch { return value; }
120+
catch (Exception ex)
121+
when (!(ex.InnerException is CircularDependencyException))
122+
{
123+
return value;
124+
}
113125
};
114126
}
115127

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Unity.Exceptions
6+
{
7+
internal class CircularDependencyException : Exception
8+
{
9+
}
10+
}

0 commit comments

Comments
 (0)