Class AggregateError
- Namespace
- FunctionalDdd
- Assembly
- FunctionalDdd.RailwayOrientedProgramming.dll
Represents an aggregate of multiple errors that occurred together. Use this when multiple independent errors need to be returned as a single failure result.
public sealed class AggregateError : Error, IEquatable<Error>
- Inheritance
-
AggregateError
- Implements
- Inherited Members
- Extension Methods
Examples
var errors = new List<Error>
{
Error.Validation("Invalid email", "email"),
Error.NotFound("User not found", userId),
Error.Domain("Insufficient balance")
};
var aggregateError = new AggregateError(errors);
Remarks
This is useful for scenarios where multiple operations fail independently, such as batch processing or parallel validation of multiple entities.
The aggregated errors can be of different types and are accessible via the Errors property. This type is immutable - the errors collection cannot be modified after creation.
Constructors
AggregateError(IReadOnlyList<Error>)
Initializes a new instance of the AggregateError class with the specified errors. Uses the default error code "aggregate.error".
public AggregateError(IReadOnlyList<Error> errors)
Parameters
errorsIReadOnlyList<Error>The collection of errors to aggregate. Must contain at least one error.
Exceptions
- ArgumentException
Thrown when
errorsis empty.
AggregateError(IReadOnlyList<Error>, string)
Initializes a new instance of the AggregateError class with the specified errors and custom error code.
public AggregateError(IReadOnlyList<Error> errors, string code)
Parameters
errorsIReadOnlyList<Error>The collection of errors to aggregate. Must contain at least one error.
codestringThe custom error code for this aggregate error.
Exceptions
- ArgumentException
Thrown when
errorsis empty.
Properties
Errors
Gets the collection of aggregated errors.
public IReadOnlyList<Error> Errors { get; }
Property Value
- IReadOnlyList<Error>
A read-only list of Error instances that were aggregated together.