-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Non transient value type error #163
Conversation
Fix wrong reference after rename Remove unnecessary method
# Conflicts: # src/Jab.FunctionalTests.Common/ContainerTests.cs
src/Jab/ContainerGenerator.cs
Outdated
valueCallback(codeWriter, w => w.Append($"{cacheLocation}")); | ||
if (serviceCallSite.ImplementationType.IsValueType) | ||
{ | ||
valueCallback(codeWriter, w => w.Append($"{cacheLocation}!.Value")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is !
required? There is an if ... == null
check right above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, but not really, it's a == default check which still causes the compiler to throw an error, I can change it to == null and remove the !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
== null
sounds good.
Thank you! |
If you register a value type as singleton or scoped you get a compile error.
The compile error happens because there's a nullable field saved for each registration, which in reference type is implicitly castable to the implementation type, but in value type you have to cast it manually or use the Value property.
The 1st commit is a Unit Test showcasing the problem