Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions DomainValidation.UnitTests/DomainValidation.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
<PackageReference Include="xunit" Version="2.9.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand All @@ -22,7 +22,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DomainValidation\DomainValidation.csproj"/>
<ProjectReference Include="..\DomainValidation\DomainValidation.csproj" />
</ItemGroup>

</Project>
13 changes: 8 additions & 5 deletions DomainValidation/DomainValidation.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Title>Domain Validation</Title>
<Authors>ipazooki</Authors>
<Authors>Mo Pazooki</Authors>
<Description>This project is an approach to domain validation with a result object.</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>exception-result.jpg</PackageIcon>
<RepositoryType>git</RepositoryType>
<PackageTags>domain-validation; validation; exception-handling</PackageTags>
<Version>2.7.0</Version>
<Version>3.0.0</Version>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>$(AssemblyName).NET</PackageId>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/iPazooki/DomainValidation</RepositoryUrl>
<AssemblyVersion>2.7.0</AssemblyVersion>
<FileVersion>2.7.0</FileVersion>
<AssemblyVersion>3.0.0</AssemblyVersion>
<FileVersion>3.0.0</FileVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Copyright>Copyright (c) $([System.DateTime]::Now.Year) Mo Pazooki</Copyright>
<PackageProjectUrl>https://github.com/iPazooki/DomainValidation</PackageProjectUrl>
<PackageReleaseNotes>Upgrade to .NET 10</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
![GitHub contributors](https://img.shields.io/github/contributors/ipazooki/DomainValidation)
![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/ipazooki/DomainValidation/dotnet.yml)

# Domain validation with returning result object
# Domain validation with a result object

This project is an approach to domain validation with a result object. The `Result` class is used to handle errors and results in your application in a consistent and reliable way. If there is no validation issue and if the model is valid, then `result.Value` will return the value which is valid model and the `result.IsSuccess` is true. However, if something is wrong with domain validation, then `result.IsSuccess` is false and `result.Error` will hold error code and description.
This library provides a simple, consistent approach to domain validation using a `Result` object. The `Result` class encapsulates both the outcome of an operation and any associated validation errors.

### Example:
- When validation passes and the model is valid, `result.IsSuccess` is `true` and `result.Value` contains the valid model.
- When validation fails, `result.IsSuccess` is `false` and `result.Errors` contains one or more `Error` instances describing what went wrong.

Here we have a `Blog` class with a domain validation logic:
## Example

```csharp
Consider a `Blog` class with basic domain validation logic:

```csharp
public class Blog
{
private Blog(string title)
{

Title = title;
}

Expand All @@ -32,12 +33,12 @@ public class Blog

if (title.Length < 3)
{
errors.Add(new Error("The minimum title length is 3 character"));
errors.Add(new Error("The minimum title length is 3 characters"));
}

if (title.Length > 40)
{
errors.Add(new Error("The maximum title length is 40 character"));
errors.Add(new Error("The maximum title length is 40 characters"));
}

if (errors.Any())
Expand All @@ -50,12 +51,12 @@ public class Blog

public string Title { get; init; }
}

```

If we create an instance of `Blog` class with a valid title, then returned resule is successful with a new instance of `Blog`, but if it's not valid, then we will receive proper error message with detailed information about error.
Creating an instance of `Blog` with a valid title returns a successful `Result<Blog>` containing the new instance. If the title is invalid, the result indicates failure and contains the corresponding error details.

```csharp
Result<Blog> blog = Blog.Create("My awesome blog");

if (blog.IsSuccess)
{
Expand All @@ -81,15 +82,15 @@ if (!blog.IsSuccess)
Console.WriteLine(error);
}
}

```

### Contribution
👍 You are encouraged to contribute to this project by forking it or giving it a star if you find it valuable :)
## Contribution

You are very welcome to contribute by opening issues, submitting pull requests, or simply giving the project a ⭐ on GitHub if you find it useful.

### Social Media
## Social media

[![Email](https://img.shields.io/badge/Email-gray?logo=gmail&style=flat-square)](mailto:ipazooki@gmail.com)
[![Email](https://img.shields.io/badge/Email-gray?logo=gmail&style=flat-square)](mailto:ipazooki@live.com)
[![Stack Overflow](https://img.shields.io/badge/Stackoverflow-gray?logo=stackoverflow&style=flat-square)](https://stackoverflow.com/users/1424065/mrp)
[![Linkedin](https://img.shields.io/badge/-LinkedIn-blue?style=flat-square&logo=Linkedin&logoColor=white&link=https://www.linkedin.com/in/pazooki)](https://www.linkedin.com/in/pazooki/)
![Twitter Follow](https://img.shields.io/twitter/follow/ipazooki)