7

Is it logical to check the null values ​​in the injected arguments?

 3 years ago
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.
neoserver,ios ssh client

Is it logical to check the null values ​​in the injected arguments?

advertisements

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

I have a JSON object that is coming from a webserver. The log is something like this: { "status":"success", "UserID":15, "Name":"John", "DisplayName":"John", "Surname":"S

How to check a null value of the return value in the ColdFusion query loop

<cfloop query="GET_ALL_STUDENTS> <cfif #student_id# is NOT NULL> <!--- do something---> </cfif> </cfloop> Above is how I am looping my cf query which returns null value and I want to check if the student_id is null or no

How to check a null value in a converter

I use an SQLDataReader to grab data from my database and instantiate the corresponding Object in code. I handle all fields that might contain nulls as follows (just a code snippet example): StartDate = If(IsDBNull(rdr(6)), Nothing, rdr.GetDateTime(6)

Best practice Javascript to check only null values

I want to check the null value in JavaScript. For instance, test() is function which could return null. So If I want to test the null check efficiently what should be my approach. var a = test(); followed by if (a) {} OR if (a !== null) {} ? since if

Java - How to handle the null value passed by an argument?

This question already has an answer here: What is a NullPointerException, and how do I fix it? 12 answers I wrote this simple function: private String getOperatorForCardinality(String op) { String operator =""; if(op!=null) { if(op.equals("

How do I check a null value in a tuple or a unique value in a column using LINQ for the Entity Framework?

I have a row that has a datetime value in it. If that value has a date, the user is confirmed and can log in. But, if the value is NULL, the user needs to find their confirmation email and click on the link to verify before log in. I need to find out

Arithmetic Extremity bash: check a null value variable

I find this behaviour counter-intuitive: v=0; ((v)) && echo K; v=1; ((v)) && echo J echoes: J but generally 0 is success: f() { return 0; }; if f; then echo W; fi Explain the reasoning? man page for (( )) says: If the value of the expressi

Explicitly check the call arguments of the function with `verify` or implicitly with` when`?

What is the best way to check that right argument comes to right place with Mockito? Consider next unit-test: @Test public void getProjectByIdTest() { Long projectId = 1L; ProjectEntity expectedProject = mock(ProjectEntity.class); when(projectReposit

The logic of null values ​​in Android programming: confused

I hope this is a very simple question, what is the Android equivalent to doing this in PHP: PHP: function BlahBlah ($first_var,$second_var,$optional_var_1=null,$optional_var_2=null) { } In Android it appears everything I feed into a function must hav

Check the null value

var entries = from video in Video.GetTopVideos().AsEnumerable() select new XElement("item", new XElement("title", video.Title), new XElement("category", video.Tags[video.Tags.Count-1].Name), //........... If the property vide

How to check the Null value in vb.net

It sounds like piece of cake, but please accept my ignorance and help me with this. I have this: If String.IsNullOrEmpty(editTransactionRow.pay_id.ToString()) = False Then stTransactionPaymentID = editTransactionRow.pay_id 'Check for null value End I

Passing a null value to the mysql database

A user fills out a form and if they choose to not fill out a field that is not required php does this: if($_SESSION['numofchildren']=="") $_SESSION['numofchildren']=null; But when I use the session variable in a mysql query, the result is not nu

The null value in the linq request throws an error of null value

I'm pulling results from a db however when there a null value in a column i'm getting an error and using convert.todatetime to format the date to display in a gridview on the page. var ua = from utilacti in db.utility_activations where utilacti.ua_ca

Manage null values ​​to avoid errors during the loop

I am using the following code to return data from a loop and although I am receiving the data it seems there may be null data also which is producing errors. Here is the code $extensions = count($cert['tbsCertificate']['extensions']); for ($j = 0; $j

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK