MindResult 2.3.1

dotnet add package MindResult --version 2.3.1
                    
NuGet\Install-Package MindResult -Version 2.3.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="MindResult" Version="2.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MindResult" Version="2.3.1" />
                    
Directory.Packages.props
<PackageReference Include="MindResult" />
                    
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 MindResult --version 2.3.1
                    
#r "nuget: MindResult, 2.3.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 MindResult@2.3.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=MindResult&version=2.3.1
                    
Install as a Cake Addin
#tool nuget:?package=MindResult&version=2.3.1
                    
Install as a Cake Tool

MindResult

MindResult kütüphanesi, işlemlerin sonucunu standart ve tip güvenli bir şekilde döndürmek için geliştirilmiş bir C# yapısıdır.
API response, servis sonuçları veya genel işlem çıktıları için kullanılabilir.


🚀 Kurulum

NuGet veya proje referansınız üzerinden ekledikten sonra, ASP.NET Core projelerinde DI ile kolayca yapılandırabilirsiniz:

// Varsayılan enum ile
services.AddMindResult();

// Kendi enum'unuzla
services.AddMindResult<ExtraFields>();

📍 Temel Sınıf Yapısı

  • IsSuccess → İşlemin başarılı olup olmadığını gösterir (bool). Varsayılan: true.

  • Message → Sonuç mesajı. Varsayılan: "OK".

  • StatusCode → HTTP benzeri durum kodu. Varsayılan: 200.

  • Data → Result<T> için döndürülen veri.

  • AdditionalFields → Ek alanları tutar (enum tabanlı anahtarlar).

var result = new Result { IsSuccess = true, Message = "Başarılı" };
var resultWithData = new Result<string>("Merhaba Dünya");

📍 CreateResult Yardımcı Sınıfı

Kolay ve standart Result üretimi için:

// Başarılı sonuç
var okResult = CreateResult.Ok("İşlem başarılı");

// Başarısız sonuç
var failResult = CreateResult.Failure("Geçersiz istek", 400);

// Data ile başarılı sonuç
var user = new { Id = 1, Name = "Ali" };
var dataResult = CreateResult.Ok(user, "Kullanıcı bulundu");

// Data ile başarısız sonuç
var failDataResult = CreateResult.Failure<object>("Kullanıcı bulunamadı", 404);

Çıktı Formatı

// AdditionalFields yok
okResult.ToDictionary()
{
  "IsSuccess": true,
  "Message": "İşlem başarılı",
  "StatusCode": 200
}

failResult.ToDictionary()
{
  "IsSuccess": false,
  "Message": "Geçersiz istek",
  "StatusCode": 400
}

dataResult.ToDictionary()
{
  "IsSuccess": true,
  "Message": "Kullanıcı bulundu",
  "StatusCode": 200,
  "Data": { "Id": 1, "Name": "Ali" }
}

📍 Ek Alanlar (AdditionalFields) ve Fluent Kullanım

With extension metodu ile enum tabanlı ek alan ekleyebilirsiniz:

public enum ExtraFields
{
    ErrorCode,
    TraceId
}

// DI veya CreateResult.ConfigureKeys<ExtraFields>() ile enum yapılandırıldıysa:
var result = CreateResult.Failure("Hatalı veri", 422)
                         .With(ExtraFields.ErrorCode, "INVALID_INPUT")
                         .With(ExtraFields.TraceId, Guid.NewGuid().ToString());

Çıktı Formatı

{
  "IsSuccess": false,
  "Message": "Hatalı veri",
  "StatusCode": 422,
  "ErrorCode": "INVALID_INPUT",
  "TraceId": "550e8400-e29b-41d4-a716-446655440000"
}

📍 Özellikler

✅ Standartlaştırılmış dönüş yapısı

✅ Tip güvenliği (Result<T>)

✅ Ok ve Failure yardımcı metotları

✅ Fluent ek alan ekleme (With)

✅ Enum tabanlı ek alan yönetimi

✅ DI ile kolay yapılandırma (AddMindResult)

✅ ToDictionary() ile JSON’a dönüştürmeye hazır yapı

📌 Notlar

CreateResult.ConfigureKeys<TEnum>() veya services.AddMindResult<TEnum>() ile hangi enum tipini kullanacağınızı belirleyin.

Ek alan ekleme (AdditionalFields) sadece enum tipleriyle yapılmalıdır.

ResultExtensions.With metodu, fluent kullanım için tasarlanmıştır.

📝 Örnek ASP.NET Core Controller Kullanımı

[ApiController]
[Route("api/[controller]")]
public class UserController : ControllerBase
{
    [HttpGet("{id}")]
    public IActionResult GetUser(int id)
    {
        var user = GetUserFromDb(id);
        if (user == null)
        {
            return Ok(CreateResult.Failure<object>("Kullanıcı bulunamadı")
                                    .With(ExtraFields.ErrorCode, "NOT_FOUND"));
        }

        return Ok(CreateResult.Ok(user, "Kullanıcı bulundu"));
    }
}
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.

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
2.3.1 150 9/16/2025
2.3.0 151 9/15/2025
2.2.0 153 9/15/2025
2.1.0 151 9/15/2025
2.0.0 155 9/15/2025
1.0.1 115 1/24/2025
1.0.0 101 1/24/2025