FGY.Kernel 1.0.2

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

Kernel NuGet Package

Ortak .NET projeleri için geliştirilmiş temel altyapı kütüphanesi. Entity Framework Core tabanlı repository pattern, dinamik sorgulama, sayfalama ve işlem sonuç yönetimi gibi standart işlevleri içerir.

📦 Kurulum

✨ Özellikler

  • Generic Repository Pattern: Async/Sync repository implementasyonları
  • Unit of Work Pattern: Transaction yönetimi
  • Dynamic Query Builder: Runtime'da dinamik sorgular oluşturma
  • Sayfalama (Pagination): Gelişmiş sayfalama desteği
  • Operation Result Pattern: Standart API yanıt yapıları
  • Custom Exception Types: İş mantığı için özelleştirilmiş exception'lar
  • Base Entity: Tüm entity'ler için ortak base class
  • Predicate Extensions: LINQ sorguları için yardımcı extension'lar

🚀 Kullanım

Dependency Injection (Program.cs)

using Microsoft.EntityFrameworkCore;
using Kernel.Repositories;

var builder = WebApplication.CreateBuilder(args);

// DbContext
builder.Services.AddDbContext<YourDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));

// Unit of Work
builder.Services.AddScoped<IUnitOfWork<YourDbContext>, UnitOfWork<YourDbContext>>();

var app = builder.Build();
app.Run();

Base Entity

using Kernel.Domain;

public class Product : Entity<Guid>
{
    public string Name { get; set; }
    public decimal Price { get; set; }
    
    public Product() : base() { }
}

Repository Pattern

using Kernel.Repositories;
using Microsoft.EntityFrameworkCore;

// Repository interface
public interface IProductRepository : IAsyncRepository<Product, Guid>
{
}

// Repository implementasyonu
public class ProductRepository : EfRepositoryBase<Product, Guid, YourDbContext>, IProductRepository
{
    public ProductRepository(YourDbContext context) : base(context)
    {
    }
}

Async Repository Kullanımı

// Tekil kayıt getirme
var product = await _productRepository.GetAsync(
    predicate: p => p.Id == productId,
    include: q => q.Include(p => p.Category),
    enableTracking: false
);

// Liste getirme
var products = await _productRepository.GetListAsync(
    predicate: p => p.Price > 100,
    orderBy: q => q.OrderBy(p => p.Name),
    index: 0,
    size: 10
);

// Ekleme
var newProduct = new Product { Name = "Test", Price = 99.99m };
await _productRepository.AddAsync(newProduct);

// Güncelleme
product.Name = "Updated Name";
await _productRepository.UpdateAsync(product);

// Silme
await _productRepository.DeleteAsync(product);

Dynamic Query

using Kernel.Repositories.DynamicActions;

var dynamic = new Dynamic
{
    Filter = new Filter
    {
        Field = "Name",
        Operator = "contains",
        Value = "Test"
    },
    Sort = new List<Sort>
    {
        new Sort { Field = "Price", Dir = "asc" }
    }
};

var result = await _productRepository.GetListByDynamicAsync(
    dynamic: dynamic,
    index: 0,
    size: 10
);

Pagination (Sayfalama)

using Kernel.OperationResults.Paging;

// Sayfalanmış sonuç
IPaginate<Product> paginatedProducts = await _productRepository.GetListAsync(
    predicate: p => p.IsActive,
    index: 0,  // Sayfa numarası
    size: 20   // Sayfa başına kayıt
);

// Sayfalama bilgileri
int totalCount = paginatedProducts.Count;
int totalPages = paginatedProducts.Pages;
int currentIndex = paginatedProducts.Index;
IList<Product> items = paginatedProducts.Items;

Operation Result Pattern

using Kernel.OperationResults;

public class ProductService
{
    public async Task<OperationResult<Product>> CreateProductAsync(CreateProductDto dto)
    {
        try
        {
            var product = new Product { Name = dto.Name, Price = dto.Price };
            await _repository.AddAsync(product);
            await _unitOfWork.SaveChangesAsync();
            
            return OperationResult<Product>.Success(product, "Ürün başarıyla oluşturuldu");
        }
        catch (Exception ex)
        {
            return OperationResult<Product>.Failure(ex.Message);
        }
    }
}

// Kullanımı
var result = await _productService.CreateProductAsync(dto);

if (result.IsSuccessful)
{
    var product = result.Data;
    // Success case
}
else
{
    var errorMessage = result.Message;
    // Error case
}

Unit of Work

using Kernel.Repositories;

public class YourUnitOfWork : UnitOfWork
{
    public IProductRepository Products { get; }
    public ICategoryRepository Categories { get; }
    
    public YourUnitOfWork(YourDbContext context, 
                          IProductRepository productRepository,
                          ICategoryRepository categoryRepository) 
        : base(context)
    {
        Products = productRepository;
        Categories = categoryRepository;
    }
}

// Kullanımı
await _unitOfWork.Products.AddAsync(product);
await _unitOfWork.Categories.AddAsync(category);
await _unitOfWork.SaveChangesAsync(); // Transaction

Custom Exceptions

using Kernel.Exceptions;

// İş mantığı hatası
throw new BusinessException("Stok yetersiz");

// Doğrulama hatası
throw new ValidationException("Email formatı geçersiz");

// Kayıt bulunamadı
throw new NotFoundException($"Product with ID {id} not found");

// Yetkilendirme hatası
throw new AuthorizationException("Bu işlem için yetkiniz yok");

// Bad Request
throw new BadRequestException("Geçersiz parametre");

Predicate Extensions

using Kernel.Extensions;

Expression<Func<Product, bool>> expr1 = p => p.IsActive;
Expression<Func<Product, bool>> expr2 = p => p.Price > 100;

// İki predicate'i birleştirme (AND)
var combined = expr1.AndAlso(expr2);
// Result: p => p.IsActive && p.Price > 100

var products = await _repository.GetListAsync(predicate: combined);

🏗️ Proje Yapısı

Kernel/
├── Domain/                    # Entity base sınıfları
│   ├── BaseEntity.cs
│   └── IBaseEntity.cs
├── Exceptions/                # Custom exception türleri
│   ├── AuthorizationException.cs
│   ├── BadRequestException.cs
│   ├── BusinessException.cs
│   ├── NotFoundException.cs
│   └── ValidationException.cs
├── Extensions/                # Yardımcı extension metodları
│   └── PredicateExtensions.cs
├── OperationResults/          # API yanıt yapıları
│   ├── ErrorResult.cs
│   ├── IOperationResult.cs
│   ├── NoContentResult.cs
│   ├── OperationResult.cs
│   └── Paging/               # Sayfalama
│       ├── IPaginate.cs
│       ├── Paginate.cs
│       └── Extensions...
└── Repositories/              # Repository pattern
    ├── IAsyncRepository.cs
    ├── IRepository.cs
    ├── IUnitOfWork.cs
    ├── Concrete/
    │   ├── EfRepositoryBase.cs
    │   └── UnitOfWork.cs
    └── DynamicActions/       # Dinamik sorgular
        ├── Dynamic.cs
        ├── Filter.cs
        └── Sort.cs

🔧 Gereksinimler

  • .NET 8.0+
  • Entity Framework Core 8.0+
  • System.Linq.Dynamic.Core 1.7+

📄 Lisans

Bu proje kişisel/ticari kullanım için geliştirilmiştir.

🤝 Katkıda Bulunma

Ortak projelerinizde kullanmak için tasarlanmış bu kütüphaneye katkılarınızı bekliyoruz.

📧 İletişim

Sorularınız için issue açabilirsiniz.


Not: Bu kütüphane, .NET projelerinde tekrar eden kod yazımını azaltmak ve standart bir altyapı sağlamak için tasarlanmıştır.

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.  net9.0 was computed.  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
1.0.2 149 1/27/2026
1.0.1 132 1/13/2026
1.0.0 315 12/17/2025