BridgingIT.DevKit.Common.Abstractions 3.0.3-preview.0.36

This is a prerelease version of BridgingIT.DevKit.Common.Abstractions.
There is a newer version of this package available.
See the version list below for details.
dotnet add package BridgingIT.DevKit.Common.Abstractions --version 3.0.3-preview.0.36                
NuGet\Install-Package BridgingIT.DevKit.Common.Abstractions -Version 3.0.3-preview.0.36                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BridgingIT.DevKit.Common.Abstractions" Version="3.0.3-preview.0.36" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BridgingIT.DevKit.Common.Abstractions --version 3.0.3-preview.0.36                
#r "nuget: BridgingIT.DevKit.Common.Abstractions, 3.0.3-preview.0.36"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install BridgingIT.DevKit.Common.Abstractions as a Cake Addin
#addin nuget:?package=BridgingIT.DevKit.Common.Abstractions&version=3.0.3-preview.0.36&prerelease

// Install BridgingIT.DevKit.Common.Abstractions as a Cake Tool
#tool nuget:?package=BridgingIT.DevKit.Common.Abstractions&version=3.0.3-preview.0.36&prerelease                

bITDevKit

Empowering developers with modular components for modern application development, centered around Domain-Driven Design principles.

Our goal is to empower developers by offering modular components that can be easily integrated into your projects. Whether you're working with repositories, commands, queries, or other components, the bITDevKit provides flexible solutions that can adapt to your specific needs.

This repository includes the complete source code for the bITDevKit, along with a variety of sample applications located in the ./examples folder within the solution. These samples serve as practical demonstrations of how to leverage the capabilities of the bITDevKit in real-world scenarios. All components are available as nuget packages.

For the latest updates and release notes, please refer to the RELEASES.

Join us in advancing the world of software development with the bITDevKit!


Result.cs Overview

The Result class encapsulates the outcome of an operation, promoting an expressive and error-tolerant way to handle success and failure states.

The Result class is a central component designed to encapsulate the outcome of an operation, providing a way to represent both successful and failed operations. This class promotes a more expressive and error-tolerant approach to handling operation results, encouraging the explicit declaration of success or failure states.

Returning a Result

To return a Result from a method, you typically define the method to return Result or Result<T>, where T is the type of the value returned in case of success. Here is an example method returning a Result:

public Result PerformOperation()
{
    // Your logic here
    
    if (success)
    {
        return Result.Success();
    }
    else
    {
        return Result.Failure(new Error("Operation Failed"));
    }
}

Handling a Result

When you receive a Result from a method, you can handle it by checking its success or failure state. Here's an example:

var result = PerformOperation();

if (result.IsSuccess)
{
    // Handle success
}
else
{
    // Handle failure
    var error = result.Error;
    Console.WriteLine(error.Message);
}

Using Typed Results

Sometimes, you may want to return a result with a value. This is where Result<T> comes in handy:

public Result<int> CalculateSum(int a, int b)
{
    if (a < 0 || b < 0)
    {
        return Result.Failure<int>(new Error("Inputs must be non-negative"));
    }

    return Result.Success(a + b);
}

Handling a Result<T> involves extracting the value if the operation was successful:

var result = CalculateSum(5, 10);

if (result.IsSuccess)
{
    int sum = result.Value;
    Console.WriteLine($"Sum: {sum}");
}
else
{
    Console.WriteLine(result.Error.Message);
}

Typed Errors

Typed errors provide a more specific and structured way to handle different error scenarios. For example, the EntityNotFoundResultError class can be used to represent an error where an entity is not found:

EntityNotFoundResultError.cs:
public class EntityNotFoundResultError : Error
{
    public EntityNotFoundResultError(string entityName, object key)
        : base($"Entity '{entityName}' with key '{key}' was not found.")
    {
    }
}

You can return this typed error as follows:

public Result GetEntity(int id)
{
    var entity = repository.FindById(id);

    if (entity == null)
    {
        return Result.Failure(new EntityNotFoundResultError("EntityName", id));
    }

    return Result.Success(entity);
}

When handling the result, you can check if the error is of a specific type:

var result = GetEntity(1);

if (result.IsSuccess)
{
    // Handle success
}
else if (result.Error is EntityNotFoundResultError)
{
    var error = (EntityNotFoundResultError)result.Error;
    Console.WriteLine(error.Message);
}
else
{
    // Handle other errors
}

Other available typed errors are:

By using typed errors, you can create more expressive and manageable error handling in your application.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (13)

Showing the top 5 NuGet packages that depend on BridgingIT.DevKit.Common.Abstractions:

Package Downloads
BridgingIT.DevKit.Common.Utilities

BridgingIT DevKit: Empowering developers with modular components for modern application development, centered around Domain-Driven Design principles. Our goal is to empower developers by offering modular components that can be easily integrated into your projects. Whether you're working with repositories, commands, queries, or other components, the bITDevKit provides flexible solutions that can adapt to your specific needs.

BridgingIT.DevKit.Common.Serialization

BridgingIT DevKit: Empowering developers with modular components for modern application development, centered around Domain-Driven Design principles. Our goal is to empower developers by offering modular components that can be easily integrated into your projects. Whether you're working with repositories, commands, queries, or other components, the bITDevKit provides flexible solutions that can adapt to your specific needs.

BridgingIT.DevKit.Domain

BridgingIT DevKit: Empowering developers with modular components for modern application development, centered around Domain-Driven Design principles. Our goal is to empower developers by offering modular components that can be easily integrated into your projects. Whether you're working with repositories, commands, queries, or other components, the bITDevKit provides flexible solutions that can adapt to your specific needs.

BridgingIT.DevKit.Application.Messaging

BridgingIT DevKit: Empowering developers with modular components for modern application development, centered around Domain-Driven Design principles. Our goal is to empower developers by offering modular components that can be easily integrated into your projects. Whether you're working with repositories, commands, queries, or other components, the bITDevKit provides flexible solutions that can adapt to your specific needs.

BridgingIT.DevKit.Application.Storage

BridgingIT DevKit: Empowering developers with modular components for modern application development, centered around Domain-Driven Design principles. Our goal is to empower developers by offering modular components that can be easily integrated into your projects. Whether you're working with repositories, commands, queries, or other components, the bITDevKit provides flexible solutions that can adapt to your specific needs.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.4-preview.0.29 34 11/21/2024
3.0.4-preview.0.28 51 11/19/2024
3.0.4-preview.0.27 34 11/19/2024
3.0.4-preview.0.23 31 11/19/2024
3.0.4-preview.0.21 30 11/19/2024
3.0.4-preview.0.20 34 11/18/2024
3.0.4-preview.0.19 45 11/18/2024
3.0.4-preview.0.18 29 11/18/2024
3.0.4-preview.0.17 32 11/18/2024
3.0.4-preview.0.16 36 11/15/2024
3.0.4-preview.0.15 36 11/15/2024
3.0.4-preview.0.14 51 11/2/2024
3.0.4-preview.0.13 44 10/29/2024
3.0.4-preview.0.12 38 10/29/2024
3.0.4-preview.0.8 46 10/29/2024
3.0.4-preview.0.7 43 10/29/2024
3.0.4-preview.0.6 36 10/24/2024
3.0.4-preview.0.5 46 10/23/2024
3.0.4-preview.0.4 37 10/23/2024
3.0.4-preview.0.3 39 10/23/2024
3.0.4-preview.0.2 43 10/23/2024
3.0.4-preview.0.1 88 10/16/2024
3.0.3 351 10/11/2024
3.0.3-preview.0.56 56 10/10/2024
3.0.3-preview.0.55 50 10/10/2024
3.0.3-preview.0.54 51 10/10/2024
3.0.3-preview.0.50 50 10/10/2024
3.0.3-preview.0.49 65 10/9/2024
3.0.3-preview.0.44 71 10/8/2024
3.0.3-preview.0.43 44 10/8/2024
3.0.3-preview.0.42 42 10/7/2024
3.0.3-preview.0.41 48 10/7/2024
3.0.3-preview.0.40 81 10/1/2024
3.0.3-preview.0.39 55 10/1/2024
3.0.3-preview.0.38 49 10/1/2024
3.0.3-preview.0.36 55 9/30/2024
3.0.3-preview.0.35 67 9/26/2024
3.0.3-preview.0.34 63 9/26/2024
3.0.3-preview.0.33 50 9/26/2024
3.0.3-preview.0.32 80 9/24/2024
3.0.3-preview.0.31 306 9/10/2024
3.0.3-preview.0.30 52 9/9/2024
3.0.3-preview.0.29 49 9/9/2024
3.0.3-preview.0.28 41 9/8/2024
3.0.3-preview.0.27 58 9/5/2024
3.0.3-preview.0.26 59 9/3/2024
3.0.3-preview.0.25 52 9/3/2024
3.0.3-preview.0.24 60 9/3/2024
3.0.3-preview.0.23 74 8/21/2024
3.0.3-preview.0.22 39 7/29/2024
3.0.3-preview.0.21 61 7/25/2024
3.0.3-preview.0.18 63 7/12/2024
3.0.3-preview.0.17 51 7/12/2024
3.0.3-preview.0.16 43 7/12/2024
3.0.3-preview.0.15 48 7/5/2024
3.0.3-preview.0.14 101 6/24/2024
3.0.3-preview.0.13 76 6/23/2024
3.0.3-preview.0.12 65 6/21/2024
3.0.3-preview.0.11 65 6/20/2024
3.0.3-preview.0.9 350 5/27/2024
3.0.3-preview.0.8 59 5/27/2024
3.0.3-preview.0.7 90 5/17/2024
3.0.3-preview.0.6 64 5/14/2024
3.0.3-preview.0.5 96 5/8/2024
3.0.3-preview.0.3 90 5/6/2024
3.0.3-preview.0.1 71 4/25/2024
3.0.2 882 4/25/2024
3.0.2-preview.0.4 82 4/25/2024
3.0.2-preview.0.3 135 4/25/2024
3.0.2-preview.0.2 87 4/25/2024
3.0.2-preview.0.1 65 4/25/2024
3.0.1 416 4/25/2024
3.0.1-preview.0.10 68 4/24/2024
3.0.1-preview.0.9 175 4/19/2024
3.0.1-preview.0.8 59 4/24/2024
3.0.1-preview.0.7 122 4/24/2024

## Release 3.0.1 [25.04.24]

- [N] Initial release

-----

- [N] New
- [M] Modified
- [B] Breaking