Skip to content

Standardize null checks in constructor assignments #533

@ziagham

Description

@ziagham

What version of FlowSynx?

1.2.1

Describe the bug

File: FlowSynx.Application/Features/Workflows/Command/AddWorkflow/AddWorkflowHandler.cs lines: 38-53

The constructor currently mixes ArgumentNullException.ThrowIfNull(param) calls with direct assignments, sometimes adding redundant ?? throw checks. To improve readability and consistency, we should standardize all assignments to use the _field = param ?? throw new ArgumentNullException(nameof(param)) pattern.

Current code snippet:

ArgumentNullException.ThrowIfNull(logger);
ArgumentNullException.ThrowIfNull(transactionService);
ArgumentNullException.ThrowIfNull(workflowService);
ArgumentNullException.ThrowIfNull(currentUserService);
ArgumentNullException.ThrowIfNull(jsonDeserializer);
ArgumentNullException.ThrowIfNull(workflowValidator);
ArgumentNullException.ThrowIfNull(workflowSchemaValidator);
ArgumentNullException.ThrowIfNull(localization);
_logger = logger;
_transactionService = transactionService;
_workflowService = workflowService;
_currentUserService = currentUserService;
_jsonDeserializer = jsonDeserializer;
_workflowValidator = workflowValidator;
_workflowSchemaValidator = workflowSchemaValidator ?? throw new ArgumentNullException(nameof(workflowSchemaValidator));
_localization = localization;

Proposed change:

Replace all ThrowIfNull calls and assignments with direct assignments using null-coalescing checks:

_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_transactionService = transactionService ?? throw new ArgumentNullException(nameof(transactionService));
_workflowService = workflowService ?? throw new ArgumentNullException(nameof(workflowService));
_currentUserService = currentUserService ?? throw new ArgumentNullException(nameof(currentUserService));
_jsonDeserializer = jsonDeserializer ?? throw new ArgumentNullException(nameof(jsonDeserializer));
_workflowValidator = workflowValidator ?? throw new ArgumentNullException(nameof(workflowValidator));
_workflowSchemaValidator = workflowSchemaValidator ?? throw new ArgumentNullException(nameof(workflowSchemaValidator));
_localization = localization ?? throw new ArgumentNullException(nameof(localization));

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions