{"id":33241666,"url":"https://github.com/Qowaiv/Qowaiv","last_synced_at":"2025-11-26T10:01:43.277Z","repository":{"id":13217327,"uuid":"15901531","full_name":"Qowaiv/Qowaiv","owner":"Qowaiv","description":"Qowaiv is a Single Value Object library","archived":false,"fork":false,"pushed_at":"2025-11-01T09:26:27.000Z","size":9361,"stargazers_count":96,"open_issues_count":11,"forks_count":14,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-11-01T11:22:55.526Z","etag":null,"topics":["ddd","domain-driven-design","value-object"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Qowaiv.png","metadata":{"files":{"readme":"README.Custom.SVO.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2014-01-14T12:38:29.000Z","updated_at":"2025-11-01T09:26:25.000Z","dependencies_parsed_at":"2023-02-19T08:00:47.938Z","dependency_job_id":"2fb985e8-28f6-4951-ac54-ad556804135c","html_url":"https://github.com/Qowaiv/Qowaiv","commit_stats":null,"previous_names":["corniel/qowaiv"],"tags_count":63,"template":false,"template_full_name":null,"purl":"pkg:github/Qowaiv/Qowaiv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qowaiv%2FQowaiv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qowaiv%2FQowaiv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qowaiv%2FQowaiv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qowaiv%2FQowaiv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Qowaiv","download_url":"https://codeload.github.com/Qowaiv/Qowaiv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qowaiv%2FQowaiv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286079811,"owners_count":27282121,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-26T02:00:06.075Z","response_time":193,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ddd","domain-driven-design","value-object"],"created_at":"2025-11-16T20:00:39.858Z","updated_at":"2025-11-26T10:01:43.270Z","avatar_url":"https://github.com/Qowaiv.png","language":"C#","funding_links":[],"categories":["Architectural Patterns"],"sub_categories":["Domain Driven Design - Domain Centric"],"readme":"# Custom Single Value Object\nCreating SVO's for the scope of (just) a project, might feel like a burden that\nis not worth the effort. Although Qowaiv has as [code generator](https://github.com/Qowaiv/qowaiv-codegenerator),\nit still results in quite some lines of code (easily 400), that needs\nmaintenance, and unit test coverage.\n\nAnother way to deal with this, is by providing a generic SVO where the actual\nbehavior is injectable. Qowaiv has two flavors: `Id\u003cTIdBehavior\u003e` and\n`Svo\u003cTSvoBehavior\u003e`. In this document we focus on the latter. \n\n``` C#\npublic sealed class ForMyCustomSvo : SvoBehavior { /* .. */ }\n\npublic class MyModel\n{\n    public Svo\u003cForMyCustomSvo\u003e MyProperty { get; init; }\n}\n```\n\nWith (global) `using` statements, this can be improved a lot:\n\n``` C#\nglobal using MyCustomSvo = Qowaiv.Svo\u003cForMyCustomSvo\u003e;\n\npublic class MyModel\n{\n    public MyCustomSvo MyProperty { get; init; }\n}\n```\n\nJust having this definition might prevent some primitive obsession, but\nwith implementing some custom behavior, we can achieve some nice results.\n\n\n## Validation\nEnsuring the validness of a SVO is key. The following mechanisms are provided:\n\n### Setting the minimum and/or maximum length\nBy simply setting the `MinLength` and/or the `MaxLength` strings exceeding\nthese constrains are rejected:\n\n``` C#\npublic sealed class ForMySvo : SvoBehavior\n{\n    public override int MinLength =\u003e 3;\n    public override int MaxLength =\u003e 9;\n}\n```\n\n### A regular expression pattern\nIf defined, the `Regex` pattern can act as a second line of defense. As in the\nfollowing example, where we ensure that all characters that make up the SVO are\nalphanumeric:\n\n``` C#\npublic sealed class ForMySvo : SvoBehavior\n{\n    public override Regex Pattern =\u003e new(\"^([A-Z][0-9])+$\");\n}\n```\n\n### Overriding the validation method\nFor more complex scenarios, the first options provided might not be sufficient.\nTherefore, is also possible to override `IsValid()`:\n\n``` C#\npublic sealed class ForMySvo : SvoBehavior\n{\n    public override bool IsValid(string str, IFormatProvider? formatProvider, out string validated)\n    {\n        if (long.TryParse(str, out var number))\n        {\n            validated = number.ToString(\"000\");\n            return true;\n        }\n        else\n        {\n            validated = default;\n            return false;\n        }\n    }\n}\n```\n\n### Normalizing input\nBefore the input string is validated, the `NormalizeInput()` method is called.\nBy default the input is trimmed, but if preferred, extra measures can be taken:\n\n```  C#\npublic sealed class ForMySvo : SvoBehavior\n{\n    public override string NormalizeInput(string str, IFormatProvider formatProvider) \n        =\u003e str?.Replace(\"-\", \"\").ToUpperInvariant()\n        ?? string.Empty;\n}\n```\n\n## Formatting\nBy default the formatting is simple: `string.Empty` for the empty state, `\"?\"`\nfor the unknown state, and the internally stored string for the rest. The empty\nstate behavior is not overridable, the other two are:\n\n```  C#\npublic sealed class ForMySvo : SvoBehavior\n{\n    public override string FormatUnknown(string? format, IFormatProvider? formatProvider) \n        =\u003e \"Unknown\";\n\n    public override string Format(string str, string? format, IFormatProvider? formatProvider)\n        =\u003e format == \"l\"\n        ? str.ToLower()\n        : str;\n}\n```\n\n## Limitations\nIt should be pointed out that this approach has its limitations. Defining extra\nproperties on a `Svo\u003cTSvoBehavior\u003e` is not possible, neither are casts,\noperation overloads or factory methods. Extra methods are, but only as extension\nmethods.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FQowaiv%2FQowaiv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FQowaiv%2FQowaiv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FQowaiv%2FQowaiv/lists"}