Ashab.Toolkit 0.1.1

dotnet add package Ashab.Toolkit --version 0.1.1
                    
NuGet\Install-Package Ashab.Toolkit -Version 0.1.1
                    
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="Ashab.Toolkit" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ashab.Toolkit" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="Ashab.Toolkit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Ashab.Toolkit --version 0.1.1
                    
#r "nuget: Ashab.Toolkit, 0.1.1"
                    
#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.
#:package Ashab.Toolkit@0.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Ashab.Toolkit&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=Ashab.Toolkit&version=0.1.1
                    
Install as a Cake Tool

<p align="center"> <img src="icon.png" alt="Ashab.Toolkit" width="120" /> </p>

Ashab.Toolkit

NuGet License: MIT

Kumpulan utilities pribadi yang dipakai ulang di berbagai project .NET Ashab: Result<T> pattern, guard clauses, dan extension methods umum.

Instalasi

dotnet add package Ashab.Toolkit

Fitur

Result Pattern

using Ashab.Toolkit.Results;

Result<User> GetUser(int id)
{
    var user = _repository.Find(id);
    return user is null
        ? Result.Failure<User>("User tidak ditemukan")
        : Result.Success(user);
}

Guard Clauses

using Ashab.Toolkit.Guards;

public Order(string customerName, int quantity)
{
    CustomerName = Guard.NotNullOrWhiteSpace(customerName, nameof(customerName));
    Quantity = Guard.Positive(quantity, nameof(quantity));
}

Extension Methods

using Ashab.Toolkit.Extensions;

"Hello World".ToSlug();        // "hello-world"
"Judul artikel panjang".Truncate(10); // "Judul arti..."

Contoh Nyata: Validasi di ASP.NET Core Endpoint

Pola ini dipakai di beberapa project produksi Ashab untuk memvalidasi input tanpa if (string.IsNullOrWhiteSpace(...)) berulang, sambil tetap menjaga response HTTP yang konsisten:

using Ashab.Toolkit.Guards;

app.MapPost("/api/login", (LoginRequest req) =>
{
    bool passwordCocok;
    try
    {
        Guard.NotNullOrWhiteSpace(req.Password, nameof(req.Password));
        passwordCocok = VerifyPassword(req.Password, storedHash);
    }
    catch (ArgumentException)
    {
        // Password kosong diperlakukan sama seperti password salah
        return Results.BadRequest("Password salah");
    }

    return passwordCocok
        ? Results.Ok()
        : Results.BadRequest("Password salah");
});

Contoh lain — validasi daftar sebelum diproses, dibungkus Result<T> supaya caller tinggal cek IsSuccess:

using Ashab.Toolkit.Guards;
using Ashab.Toolkit.Results;

Result<List<string>> SanitizeExceptions(List<string>? exceptions)
{
    try
    {
        Guard.NotEmpty(exceptions, nameof(exceptions));
        return Result.Success(exceptions!);
    }
    catch (ArgumentException ex)
    {
        return Result.Failure<List<string>>(ex.Message);
    }
}

Dipakai Di

Ashab.Toolkit sudah diadopsi (tanpa regresi) di beberapa project produksi:

  • Platform keuangan — Guard untuk validasi input & Result<T> untuk alur validasi bertahap.
  • Platform edukasi — Guard.NotEmpty/Guard.Positive untuk validasi bisnis, Result/Result<T> menggantikan pola null-return dan beberapa throw manual.
  • Platform e-commerce — Guard.NotNullOrWhiteSpace menggantikan validasi manual berulang, ToSlug() untuk normalisasi slug produk di sisi server.
  • Platform file storage — Guard untuk validasi argumen di lapisan service, Result<T> untuk kegagalan alur bisnis (konflik state tetap pakai exception agar status code HTTP terjaga), dipetakan ke response error yang konsisten lewat middleware & extension helper khusus.

Setiap adopsi diverifikasi lewat test suite project masing-masing (semua tetap hijau setelah migrasi) sebelum digabungkan.

Setup di Repo dengan Banyak Project

Kalau repo kamu punya beberapa .csproj (API, Application, Infrastructure, dst), kelola versi Ashab.Toolkit di satu tempat lewat Central Package Management:


<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>
  <ItemGroup>
    <PackageVersion Include="Ashab.Toolkit" Version="0.1.0" />
  </ItemGroup>
</Project>

Lalu di tiap .csproj cukup referensi tanpa versi:

<ItemGroup>
  <PackageReference Include="Ashab.Toolkit" />
</ItemGroup>

Update versi cukup di satu baris Directory.Packages.props, otomatis berlaku ke semua project dalam repo yang sama.

Build & Test

dotnet build
dotnet test

Pack

dotnet pack src/Ashab.Toolkit -c Release -o ./nupkg

Lisensi

MIT © Ashab

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

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.1 116 8/26/2026
0.1.0 102 8/26/2026