From 66ed9d1ad1710be8bfda8f8b41ed4471110696e9 Mon Sep 17 00:00:00 2001 From: Joao Sa Date: Mon, 18 May 2020 19:25:11 -0300 Subject: [PATCH 1/3] Enable RESOLVE_OPEN_GENERICS in tests --- tests/TinyIoC.Tests/TinyIoCTests.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/TinyIoC.Tests/TinyIoCTests.cs b/tests/TinyIoC.Tests/TinyIoCTests.cs index 2953df7..1926163 100644 --- a/tests/TinyIoC.Tests/TinyIoCTests.cs +++ b/tests/TinyIoC.Tests/TinyIoCTests.cs @@ -13,6 +13,12 @@ // FITNESS FOR A PARTICULAR PURPOSE. //=============================================================================== +#region Preprocessor Directives + +#define RESOLVE_OPEN_GENERICS // Platform supports resolving open generics + +#endregion + using System; using System.Collections.Generic; using System.Linq; From 4ee258cc272b4e855229e0a73f266755a2e28976 Mon Sep 17 00:00:00 2001 From: Joao Sa Date: Mon, 18 May 2020 19:25:44 -0300 Subject: [PATCH 2/3] Fix Child Container Resolve for Types with Generic Interfaces --- src/TinyIoC/TinyIoC.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/TinyIoC/TinyIoC.cs b/src/TinyIoC/TinyIoC.cs index d6646e5..b52822f 100644 --- a/src/TinyIoC/TinyIoC.cs +++ b/src/TinyIoC/TinyIoC.cs @@ -3716,23 +3716,26 @@ private ObjectFactoryBase GetParentObjectFactory(TypeRegistration registration) ObjectFactoryBase factory; + if (_Parent._RegisteredTypes.TryGetValue(registration, out factory)) + { + return factory.GetFactoryForChildContainer(registration.Type, _Parent, this); + } + +#if RESOLVE_OPEN_GENERICS + // Attempt container resolution of open generic if (registration.Type.IsGenericType()) { - var openTypeRegistration = new TypeRegistration(registration.Type, + var openTypeRegistration = new TypeRegistration(registration.Type.GetGenericTypeDefinition(), registration.Name); if (_Parent._RegisteredTypes.TryGetValue(openTypeRegistration, out factory)) { - return factory.GetFactoryForChildContainer(openTypeRegistration.Type, _Parent, this); + return factory.GetFactoryForChildContainer(registration.Type, _Parent, this); } return _Parent.GetParentObjectFactory(registration); } - - if (_Parent._RegisteredTypes.TryGetValue(registration, out factory)) - { - return factory.GetFactoryForChildContainer(registration.Type, _Parent, this); - } +#endif return _Parent.GetParentObjectFactory(registration); } From 7f7417fa2b3a5bc00b9bd39103e9c99380fac8d3 Mon Sep 17 00:00:00 2001 From: Chris Charabaruk Date: Mon, 23 Nov 2020 12:41:55 -0500 Subject: [PATCH 3/3] Enable RESOLVE_OPEN_GENERICS tests for supporting platforms --- tests/TinyIoC.Tests/TinyIoC.Tests.csproj | 2 +- tests/TinyIoC.Tests/TinyIoCTests.cs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/TinyIoC.Tests/TinyIoC.Tests.csproj b/tests/TinyIoC.Tests/TinyIoC.Tests.csproj index 98a64d4..a2cc581 100644 --- a/tests/TinyIoC.Tests/TinyIoC.Tests.csproj +++ b/tests/TinyIoC.Tests/TinyIoC.Tests.csproj @@ -16,7 +16,7 @@ - TRACE;MOQ + TRACE;MOQ;RESOLVE_OPEN_GENERICS diff --git a/tests/TinyIoC.Tests/TinyIoCTests.cs b/tests/TinyIoC.Tests/TinyIoCTests.cs index 1926163..11b57fd 100644 --- a/tests/TinyIoC.Tests/TinyIoCTests.cs +++ b/tests/TinyIoC.Tests/TinyIoCTests.cs @@ -15,7 +15,10 @@ #region Preprocessor Directives -#define RESOLVE_OPEN_GENERICS // Platform supports resolving open generics +// Skip open generics tests on platforms that don't support it +#if PocketPC || NETFX_CORE +#undef RESOLVE_OPEN_GENERICS +#endif #endregion