vendredi 17 janvier 2020

Checking dependencies for WebAPI Controller

I have a webapi controller which has some dependencies injected via Dependency injection. Now my question is do I have to check for null for these dependencies. If there is no check done then static code analysis tools flag it as an issue. I would like to know what is the general best practice to handle these scenarions. Would null object pattern be useful in this case Below is the sample code.

public ExGatewayController(ILogger logger, IUtilityHelper utilityHelper)
        {

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (utilityHelper == null)
            {
                throw new ArgumentNullException(nameof(utilityHelper));
            }
            _utilityHelper = utilityHelper;
            _logger = logger;
        }

Aucun commentaire:

Enregistrer un commentaire