-
-
Notifications
You must be signed in to change notification settings - Fork 835
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
WithProperty by expression #1123
Conversation
It doesn't look like there are any unit tests here to exercise the function. Can you add some? Thanks! |
@tillig I will try. But please tell me if the extension method is wanted in code base. If so please can you check what's wrong with the build? |
I think this is probably a reasonable extension. We have something similar for MVC controllers and using expressions for properties instead of strings can help with compilation and refactoring issues. The build appears to be failing due to nullable reference type annotations. A quick Google of the error message I'm sort of in the middle of some stuff so I can't dig in and decide yet whether this is an issue where we should add a type constraint on |
Regarding the null reference error, the I can't see a situation where a named property parameter would need to have a null value. |
Added |
Hmm, I'm not sure if Autofac's property injection should be used to set things to null. Can you give me an example? If we want to make nullable properties a thing, rather than use null-forgiving, we should change NamedParameter to accept The null-forgiving operator should really only ever be used if you know that the value cannot be null, but the compiler doesn't; it shouldn't really be used to handle situations where you just want to pass null to a type that doesn't accept it. |
Ah, yeah, that's the stuff I couldn't look up at the time. I'd agree, it's likely we don't want to allow folks to inject
You'll end up getting an exception if the lambda returns null; and you can't register null as an instance, either. I think we missed this in |
Understand. Removed the support for nullable |
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.
This looks great! Thanks!
I'm migrating from Spring.Net and I am using a lot of property assignment. I know it's not the best practice for Autofac, but good start. Cleanup can come later. I've found useful method checking that the assigned value can be actually assigned to the particular type in compile time. I'm probably sacrificing some startup performance during container build.
I have no idea, how to fix error that
propertyValue
might be null. Thanks for advice.