diff --git a/src/Jab.FunctionalTests.Common/ContainerTests.cs b/src/Jab.FunctionalTests.Common/ContainerTests.cs index d95b3de..ff6d7eb 100644 --- a/src/Jab.FunctionalTests.Common/ContainerTests.cs +++ b/src/Jab.FunctionalTests.Common/ContainerTests.cs @@ -1274,6 +1274,21 @@ public void SupportsNamedServices() internal partial class SupportsNamedServicesContainer { } + + [Fact] + public void SupportsNoneTransientValueType() + { + SupportsNoneTransientValueTypeContainer c = new(); + Assert.IsType(c.GetService()); + Assert.IsType(c.GetService()); + } + + [ServiceProvider] + [Scoped(typeof(int))] + [Singleton(typeof(float))] + internal partial class SupportsNoneTransientValueTypeContainer + { + } } } diff --git a/src/Jab/ContainerGenerator.cs b/src/Jab/ContainerGenerator.cs index a0657e4..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, @@ -38,7 +38,14 @@ private void GenerateCallSiteWithCache(CodeWriter codeWriter, string rootReferen }); } - valueCallback(codeWriter, w => w.Append($"{cacheLocation}")); + if (serviceCallSite.ImplementationType.IsValueType) + { + valueCallback(codeWriter, w => w.Append($"{cacheLocation}.Value")); + } + else + { + valueCallback(codeWriter, w => w.Append($"{cacheLocation}")); + } } else if (serviceCallSite.IsDisposable != false) {