Is it logical to check the null values in the injected arguments?
source link: https://www.codesd.com/item/is-it-logical-to-check-the-null-values-in-the-injected-arguments.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Is it logical to check the null values in the injected arguments?
I am using unity in my application. Does it make sense to check for null values in the constructor for the injected values?
public class ExampleClass
{
public ExampleClass(IExampleArgument e)
{
if (e == null)
//Do something
}
}
Shouldn't the argument be resolved already and bound to a value? and in case a problem happen, it should occur during resolving, so I either have a value here or I don't?
Does it make sense to check for null values in the constructor for the injected values?
Absolutely.
Shouldn't the argument be resolved already and bound to a value?
There's nothing forcing clients to use injection - it would be perfectly valid syntactically to call your constructor with a null
value. I'm assuming that a null
value would cause a problem later in the program, so you decide - do you want to handle the [problem in that constructor or let it occur naturally later in the program?
Related Articles
Checking a null value in Objective-C that was returned from a JSON string
How to check a null value of the return value in the ColdFusion query loop
How to check a null value in a converter
Best practice Javascript to check only null values
Java - How to handle the null value passed by an argument?
How do I check a null value in a tuple or a unique value in a column using LINQ for the Entity Framework?
Arithmetic Extremity bash: check a null value variable
Explicitly check the call arguments of the function with `verify` or implicitly with` when`?
The logic of null values in Android programming: confused
Check the null value
How to check the Null value in vb.net
Passing a null value to the mysql database
The null value in the linq request throws an error of null value
Manage null values to avoid errors during the loop
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK