From 3daba2db9718d1a5be11bf163f4363a75fd66aa4 Mon Sep 17 00:00:00 2001 From: Alon Talmi <130899578+AlonTalmi@users.noreply.github.com> Date: Sun, 17 Dec 2023 10:57:21 +0100 Subject: [PATCH 1/6] Scoped value type compile error Unit test Fix wrong reference after rename Remove unnecessary method --- src/Jab.FunctionalTests.Common/ContainerTests.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Jab.FunctionalTests.Common/ContainerTests.cs b/src/Jab.FunctionalTests.Common/ContainerTests.cs index 62f472e..a8bbee9 100644 --- a/src/Jab.FunctionalTests.Common/ContainerTests.cs +++ b/src/Jab.FunctionalTests.Common/ContainerTests.cs @@ -1241,6 +1241,19 @@ internal partial class SupportsInstancePropertyFactoriesOnModulesContainer { Func Instance = () => new ServiceImplementation(); } + + [Fact] + public void SupportsScopedValueType() + { + SupportsScopedValueTypeContainer c = new(); + Assert.IsType(c.GetService()); + } + + [ServiceProvider] + [Scoped(typeof(int))] + internal partial class SupportsScopedValueTypeContainer + { + } } } From f7ad3b882ad522f7b50eeb89e77720849792ba11 Mon Sep 17 00:00:00 2001 From: Alon Talmi <130899578+AlonTalmi@users.noreply.github.com> Date: Sun, 17 Dec 2023 11:41:25 +0100 Subject: [PATCH 2/6] Fix scoped value type resolve --- src/Jab/ContainerGenerator.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Jab/ContainerGenerator.cs b/src/Jab/ContainerGenerator.cs index 7aa4353..5e5a560 100644 --- a/src/Jab/ContainerGenerator.cs +++ b/src/Jab/ContainerGenerator.cs @@ -35,7 +35,14 @@ private void GenerateCallSiteWithCache(CodeWriter codeWriter, string rootReferen }); } - valueCallback(codeWriter, w => w.Append($"{cacheLocation}")); + if (serviceCallSite.ServiceType.IsValueType) + { + valueCallback(codeWriter, w => w.Append($"{cacheLocation}!.Value")); + } + else + { + valueCallback(codeWriter, w => w.Append($"{cacheLocation}")); + } } else if (serviceCallSite.IsDisposable != false) { From 21833e0d6e1bb55e101ae3659c9d061bf568626b Mon Sep 17 00:00:00 2001 From: Alon Talmi <130899578+AlonTalmi@users.noreply.github.com> Date: Wed, 20 Dec 2023 09:46:37 +0100 Subject: [PATCH 3/6] Support rename --- src/Jab/ContainerGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jab/ContainerGenerator.cs b/src/Jab/ContainerGenerator.cs index d83b9f0..e715fa9 100644 --- a/src/Jab/ContainerGenerator.cs +++ b/src/Jab/ContainerGenerator.cs @@ -38,7 +38,7 @@ private void GenerateCallSiteWithCache(CodeWriter codeWriter, string rootReferen }); } - if (serviceCallSite.ServiceType.IsValueType) + if (serviceCallSite.ImplementationType.IsValueType) { valueCallback(codeWriter, w => w.Append($"{cacheLocation}!.Value")); } From 6f40196d85d27f27cf6aac7fe21ed4c603431fd4 Mon Sep 17 00:00:00 2001 From: Alon Talmi <130899578+AlonTalmi@users.noreply.github.com> Date: Wed, 20 Dec 2023 09:55:57 +0100 Subject: [PATCH 4/6] Better describe the issue --- src/Jab.FunctionalTests.Common/ContainerTests.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Jab.FunctionalTests.Common/ContainerTests.cs b/src/Jab.FunctionalTests.Common/ContainerTests.cs index f9bf06e..4091899 100644 --- a/src/Jab.FunctionalTests.Common/ContainerTests.cs +++ b/src/Jab.FunctionalTests.Common/ContainerTests.cs @@ -1276,15 +1276,17 @@ internal partial class SupportsNamedServicesContainer } [Fact] - public void SupportsScopedValueType() + public void SupportsNoneTransientValueType() { - SupportsScopedValueTypeContainer c = new(); + SupportsNoneTransientValueTypeContainer c = new(); Assert.IsType(c.GetService()); + Assert.IsType(c.GetService()); } [ServiceProvider] [Scoped(typeof(int))] - internal partial class SupportsScopedValueTypeContainer + [Singleton(typeof(float))] + internal partial class SupportsNoneTransientValueTypeContainer { } } From 20616485e57b0cc3ed110abcfc231d73aa294adf Mon Sep 17 00:00:00 2001 From: Alon Talmi <130899578+AlonTalmi@users.noreply.github.com> Date: Sat, 23 Dec 2023 07:53:00 +0100 Subject: [PATCH 5/6] Fix spacing --- src/Jab.FunctionalTests.Common/ContainerTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Jab.FunctionalTests.Common/ContainerTests.cs b/src/Jab.FunctionalTests.Common/ContainerTests.cs index 4091899..ff6d7eb 100644 --- a/src/Jab.FunctionalTests.Common/ContainerTests.cs +++ b/src/Jab.FunctionalTests.Common/ContainerTests.cs @@ -1272,10 +1272,10 @@ public void SupportsNamedServices() [Singleton(typeof(IAnotherService), typeof(AnotherServiceImplementation), Name="OnlyNamed")] [Singleton(typeof(ServiceImplementationWithNamed))] internal partial class SupportsNamedServicesContainer - { - } + { + } - [Fact] + [Fact] public void SupportsNoneTransientValueType() { SupportsNoneTransientValueTypeContainer c = new(); From a8cb822fb2217040039d43bcbb8a79b1645be5f1 Mon Sep 17 00:00:00 2001 From: Alon Talmi <130899578+AlonTalmi@users.noreply.github.com> Date: Sat, 23 Dec 2023 21:43:36 +0100 Subject: [PATCH 6/6] Replace default with null and remove ! --- src/Jab/ContainerGenerator.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Jab/ContainerGenerator.cs b/src/Jab/ContainerGenerator.cs index e715fa9..5f503f0 100644 --- a/src/Jab/ContainerGenerator.cs +++ b/src/Jab/ContainerGenerator.cs @@ -24,9 +24,9 @@ private void GenerateCallSiteWithCache(CodeWriter codeWriter, string rootReferen if (serviceCallSite.Lifetime != ServiceLifetime.Transient) { var cacheLocation = GetCacheLocation(serviceCallSite.Identity); - codeWriter.Line($"if ({cacheLocation} == default)"); + codeWriter.Line($"if ({cacheLocation} == null)"); codeWriter.Line($"lock (this)"); - using (codeWriter.Scope($"if ({cacheLocation} == default)")) + using (codeWriter.Scope($"if ({cacheLocation} == null)")) { GenerateCallSite( codeWriter, @@ -40,7 +40,7 @@ private void GenerateCallSiteWithCache(CodeWriter codeWriter, string rootReferen if (serviceCallSite.ImplementationType.IsValueType) { - valueCallback(codeWriter, w => w.Append($"{cacheLocation}!.Value")); + valueCallback(codeWriter, w => w.Append($"{cacheLocation}.Value")); } else {