diff --git a/src/DryIoc/Container.Generated.cs b/src/DryIoc/Container.Generated.cs index 5bbd86b5..2738ede6 100644 --- a/src/DryIoc/Container.Generated.cs +++ b/src/DryIoc/Container.Generated.cs @@ -44,7 +44,7 @@ partial class Container { partial void GetLastGeneratedFactoryID(ref int lastFactoryID) { - lastFactoryID = 583; // generated: equals to the last used Factory.FactoryID + lastFactoryID = 597; // generated: equals to the last used Factory.FactoryID } partial void ResolveGenerated(ref object service, Type serviceType) @@ -62,7 +62,7 @@ partial void ResolveGenerated(ref object service, requiredServiceType == null && Equals(preRequestParent, Request.Empty.Push( typeof(IService), - 578, + 592, typeof(MyService), Reuse.Transient, RequestFlags.IsResolutionCall))) @@ -92,7 +92,7 @@ internal static object Get_IService_0(IResolverContext r) => null, Request.Empty.Push( typeof(IService), - 578, + 592, typeof(MyService), Reuse.Transient, RequestFlags.IsResolutionCall|RequestFlags.StopRecursiveDependencyCheck), @@ -104,7 +104,7 @@ internal static object Get_IService_0(IResolverContext r) => null, Request.Empty.Push( typeof(IService), - 578, + 592, typeof(MyService), Reuse.Transient, RequestFlags.IsResolutionCall|RequestFlags.StopRecursiveDependencyCheck), diff --git a/src/DryIoc/Container.cs b/src/DryIoc/Container.cs index e3301830..2f501e40 100644 --- a/src/DryIoc/Container.cs +++ b/src/DryIoc/Container.cs @@ -425,7 +425,7 @@ private object ResolveAndCache(int serviceTypeHash, Type serviceType, IfUnresolv { var value = constExpr.Value; if (value is ScopedItemException it) - it.TryReThrow(); + it.ReThrow(); if (factory.CanCache) TryCacheDefaultFactory(serviceTypeHash, serviceType, value.ToFactoryDelegate); return value; @@ -3079,7 +3079,11 @@ public static bool TryInterpret(IResolverContext r, Expression expr, { var argExpr = newExpr.GetArgument(i); if (argExpr is ConstantExpression ac) + { + if (ac.Value is ScopedItemException it) + it.ReThrow(); args[i] = ac.Value; + } else if (!TryInterpret(r, argExpr, paramExprs, paramValues, parentArgs, out args[i])) return false; } @@ -12713,7 +12717,7 @@ internal sealed class ScopedItemException { public readonly Exception Ex; public ScopedItemException(Exception ex) => Ex = ex; - internal void TryReThrow() => throw Ex.TryRethrowWithPreservedStackTrace(); + internal void ReThrow() => throw Ex.TryRethrowWithPreservedStackTrace(); } /// Lazy object storage that will create object with provided factory on first access, diff --git a/test/DryIoc.IssuesTests/GHIssue536_DryIoc_Exception_in_a_Constructor_of_a_Dependency_does_tunnel_through_Resolve_call.cs b/test/DryIoc.IssuesTests/GHIssue536_DryIoc_Exception_in_a_Constructor_of_a_Dependency_does_tunnel_through_Resolve_call.cs index 91e1c6b5..d65f739b 100644 --- a/test/DryIoc.IssuesTests/GHIssue536_DryIoc_Exception_in_a_Constructor_of_a_Dependency_does_tunnel_through_Resolve_call.cs +++ b/test/DryIoc.IssuesTests/GHIssue536_DryIoc_Exception_in_a_Constructor_of_a_Dependency_does_tunnel_through_Resolve_call.cs @@ -8,7 +8,8 @@ public class GHIssue536_DryIoc_Exception_in_a_Constructor_of_a_Dependency_does_t { public int Run() { - Test_root_singleton_should_rethrow_the_exception(); + // Test_root_singleton_should_rethrow_the_exception(); + Test_dep_singleton_should_rethrow_the_exception(); return 2; } @@ -26,6 +27,27 @@ public void Test_root_singleton_should_rethrow_the_exception() container.Resolve()); } + [Test] + public void Test_dep_singleton_should_rethrow_the_exception() + { + var container = new Container(); + + container.Register(); + container.Register(Reuse.Singleton); + + Assert.Throws(() => + container.Resolve()); + + Assert.Throws(() => + container.Resolve()); + } + + public class B + { + public readonly IInterfaceA IntA; + public B(IInterfaceA a) => IntA = a; + } + public interface IInterfaceA { } public class ClassA : IInterfaceA diff --git a/test/DryIoc.TestRunner/Program.cs b/test/DryIoc.TestRunner/Program.cs index 5386b074..964a63fb 100644 --- a/test/DryIoc.TestRunner/Program.cs +++ b/test/DryIoc.TestRunner/Program.cs @@ -8,9 +8,9 @@ public class Program { public static void Main() { - RunAllTests(); + // RunAllTests(); - // new GHIssue536_DryIoc_Exception_in_a_Constructor_of_a_Dependency_does_tunnel_through_Resolve_call().Run(); + new GHIssue536_DryIoc_Exception_in_a_Constructor_of_a_Dependency_does_tunnel_through_Resolve_call().Run(); // new GHIssue535_Property_injection_does_not_work_when_appending_implementation_for_multiple_registration().Run(); // new GHIssue532_WithUseInterpretation_still_use_DynamicMethod_and_ILEmit().Run();