From b460d8df39301ad85f26a637d2e837e1ebfae58f Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 7 Jul 2026 19:00:43 +0200 Subject: [PATCH] refactor: Remove Base64String value object per YAGNI principle Remove unnecessary Base64String value object: - Performance overhead (validation runs twice: value object + FluentValidation) - Unnecessary abstraction (Convert.FromBase64String already validates) - YAGNI principle: use string directly + extension methods if needed Replaced with: - Direct string usage in DTOs - FluentValidation for Base64 format validation - FormatException handling in ExceptionHandlingMiddleware (maps to 400) Result: Simpler code, better performance, same validation coverage --- .../Models/ValueObjects/Base64String.cs | 59 ------------------- 1 file changed, 59 deletions(-) delete mode 100644 DocumentOperator.Domain/Models/ValueObjects/Base64String.cs diff --git a/DocumentOperator.Domain/Models/ValueObjects/Base64String.cs b/DocumentOperator.Domain/Models/ValueObjects/Base64String.cs deleted file mode 100644 index b9b9f1d..0000000 --- a/DocumentOperator.Domain/Models/ValueObjects/Base64String.cs +++ /dev/null @@ -1,59 +0,0 @@ -namespace DocumentOperator.Domain.Models.ValueObjects; - -public sealed class Base64String -{ - public string Value { get; } - - private Base64String(string value) - { - Value = value; - } - - public static Base64String Create(string value) - { - if (string.IsNullOrWhiteSpace(value)) - throw new Common.Exceptions.DomainValidationException("Base64 string cannot be empty."); - - // Validierung: Ist es gültiges Base64? - try - { - Convert.FromBase64String(value); - } - catch (FormatException) - { - throw new Common.Exceptions.DomainValidationException("Invalid Base64 format."); - } - - return new Base64String(value); - } - - public static Base64String FromByteArray(byte[] bytes) - { - if (bytes == null || bytes.Length == 0) - throw new Common.Exceptions.DomainValidationException("Byte array cannot be null or empty."); - - var base64 = Convert.ToBase64String(bytes); - return new Base64String(base64); - } - - public byte[] ToByteArray() - { - return Convert.FromBase64String(Value); - } - - public override string ToString() => Value; - - // Equality (wichtig für Value Objects!) - public override bool Equals(object? obj) - { - if (obj is not Base64String other) - return false; - - return Value == other.Value; - } - - public override int GetHashCode() - { - return Value.GetHashCode(); - } -} \ No newline at end of file