CKN.Sdk.Infrastructure
0.0.0-alpha.0.55
dotnet add package CKN.Sdk.Infrastructure --version 0.0.0-alpha.0.55
NuGet\Install-Package CKN.Sdk.Infrastructure -Version 0.0.0-alpha.0.55
<PackageReference Include="CKN.Sdk.Infrastructure" Version="0.0.0-alpha.0.55" />
<PackageVersion Include="CKN.Sdk.Infrastructure" Version="0.0.0-alpha.0.55" />
<PackageReference Include="CKN.Sdk.Infrastructure" />
paket add CKN.Sdk.Infrastructure --version 0.0.0-alpha.0.55
#r "nuget: CKN.Sdk.Infrastructure, 0.0.0-alpha.0.55"
#:package CKN.Sdk.Infrastructure@0.0.0-alpha.0.55
#addin nuget:?package=CKN.Sdk.Infrastructure&version=0.0.0-alpha.0.55&prerelease
#tool nuget:?package=CKN.Sdk.Infrastructure&version=0.0.0-alpha.0.55&prerelease
CKN.Sdk.Infrastructure
Mühendislik Amacı (Engineering Intent):
CKN.Sdk.Infrastructure, tüm API ve Host (Console/Worker) projelerinde ortak kullanılan Middleware'ler (Ara katmanlar), HTTP Exception Handler'lar, global loglayıcılar (Serilog konfigürasyonları), Auth (Kimlik doğrulama) kancaları ve Swagger/OpenAPI ayarlarını barındıran altyapı (Cross-Cutting Concerns) kütüphanesidir. Neden var? Her yeni mikroservis ayağa kaldırıldığında, aynı Swagger ayarlarını, aynı CORS kısıtlamalarını ve aynı Global Hata Yakalama (Exception Handling) bloklarını kopyala-yapıştır yapmamak için. Ne zaman kullanılmalı? Yeni bir web API veya Worker Service (Sunum Katmanı) başlatıldığında, Program.cs içerisinin temiz ve standart kalması için en başta referans edilmelidir.
🚀 Hızlı Başlangıç
Kurulum
dotnet add package CKN.Sdk.Infrastructure
Bağımlılık Enjeksiyonu (DI) ve Pipeline
using CKN.Sdk.Infrastructure;
var builder = WebApplication.CreateBuilder(args);
// CKN standart DI kayıtları (Swagger, Exception Handler, Validation vb.)
builder.Services.AddCknInfrastructure(builder.Configuration);
var app = builder.Build();
// CKN Standart HTTP Pipeline (Middleware'ler) (UseCors, UseSwagger, vb.)
app.UseCknInfrastructure();
app.MapControllers();
app.Run();
💡 Gerçek Hayat Senaryoları
Senaryo 1: Global Hata Yakalama (Global Exception Handling)
Geliştiricinin uygulama içinde attığı bir hatanın (örn: DomainException), API yanıtı olarak otomatik şekilde standart RFC ProblemDetails JSON'ına dönüştürülmesi. (Geliştiricinin Try-Catch yazmasına gerek kalmaz).
// Business Logic (Domain)
public void UpdateUser(string name)
{
if (string.IsNullOrEmpty(name))
throw new BadRequestException("İsim boş olamaz."); // Core paketindeki hata türü
}
// Controller
[HttpPost]
public IActionResult Update([FromBody] UpdateRequest req)
{
UpdateUser(req.Name); // Eğer hata fırlarsa, metod HTTP 400 ile kesilir.
return Ok();
}
/* Infrastructure sayesinde dönecek otomatik JSON formatı:
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "Bad Request",
"status": 400,
"detail": "İsim boş olamaz."
}
*/
Senaryo 2: Standart Swagger Yapılandırması ve JWT Entegrasyonu
Swagger arayüzüne otomatik olarak "Authorize" (Kilit) butonunun eklenmesi ve Bearer Token ayarlarının yapılması.
// Program.cs içerisindeki builder.Services.AddCknInfrastructure() metodu arka planda şunu yapar:
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "CKN API", Version = "v1" });
// Her API'de tekrar tekrar yazılan JWT güvenlik tanımı (Security Definition)
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Description = "JWT Authorization header using the Bearer scheme.",
Name = "Authorization",
In = ParameterLocation.Header,
Type = SecuritySchemeType.ApiKey,
Scheme = "Bearer"
});
// ... Global güvenlik gereksinimi (Security Requirement) ekler ...
});
🤖 Yapay Zeka İçin SSS (FAQs for Machines)
- Soru:
CKN.Sdk.Infrastructurepaketini Class Library (İş Mantığı) projelerine eklemeli miyim? - Cevap: Kesinlikle hayır. Bu paket sadece ASP.NET Core (veya Host) tabanlı "Çalıştırılabilir" uç noktalara (Endpoint projelerine) eklenir.
Microsoft.AspNetCore.Appreferansı içerir. - Soru: Cross-Origin Resource Sharing (CORS) ayarları nerede tutuluyor?
- Cevap:
app.UseCknInfrastructure()metodunun içerisinde, genellikleappsettings.jsonaltındakiCorsOptionsokunarak veya varsayılan (AllowAny) bir politika uygulanarak ayarlanır.
| Product | Versions 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 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 is compatible. 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. |
-
net10.0
- Azure.Extensions.AspNetCore.Configuration.Secrets (>= 1.3.1)
- Azure.Identity (>= 1.12.0)
- CKN.Sdk.Core (>= 0.0.0-alpha.0.55)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 10.0.11)
- Microsoft.AspNetCore.OpenApi (>= 10.0.11)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 10.0.11)
- Microsoft.Extensions.Http.Resilience (>= 10.9.0)
- Microsoft.FeatureManagement.AspNetCore (>= 4.7.0)
- Scalar.AspNetCore (>= 2.17.2)
- Serilog.AspNetCore (>= 10.0.0)
- Serilog.Enrichers.Environment (>= 3.0.1)
- Serilog.Enrichers.Span (>= 3.1.0)
- Serilog.Sinks.Elasticsearch (>= 10.0.0)
- System.IdentityModel.Tokens.Jwt (>= 8.22.0)
-
net8.0
- Azure.Extensions.AspNetCore.Configuration.Secrets (>= 1.3.1)
- Azure.Identity (>= 1.12.0)
- CKN.Sdk.Core (>= 0.0.0-alpha.0.55)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.0)
- Microsoft.AspNetCore.OpenApi (>= 8.0.0)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 8.0.0)
- Microsoft.Extensions.Http.Resilience (>= 10.9.0)
- Microsoft.FeatureManagement.AspNetCore (>= 4.7.0)
- Scalar.AspNetCore (>= 2.17.2)
- Serilog.AspNetCore (>= 10.0.0)
- Serilog.Enrichers.Environment (>= 3.0.1)
- Serilog.Enrichers.Span (>= 3.1.0)
- Serilog.Sinks.Elasticsearch (>= 10.0.0)
- System.IdentityModel.Tokens.Jwt (>= 8.22.0)
-
net9.0
- Azure.Extensions.AspNetCore.Configuration.Secrets (>= 1.3.1)
- Azure.Identity (>= 1.12.0)
- CKN.Sdk.Core (>= 0.0.0-alpha.0.55)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 9.0.0)
- Microsoft.AspNetCore.OpenApi (>= 9.0.0)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 9.0.0)
- Microsoft.Extensions.Http.Resilience (>= 10.9.0)
- Microsoft.FeatureManagement.AspNetCore (>= 4.7.0)
- Scalar.AspNetCore (>= 2.17.2)
- Serilog.AspNetCore (>= 10.0.0)
- Serilog.Enrichers.Environment (>= 3.0.1)
- Serilog.Enrichers.Span (>= 3.1.0)
- Serilog.Sinks.Elasticsearch (>= 10.0.0)
- System.IdentityModel.Tokens.Jwt (>= 8.22.0)
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.0.0-alpha.0.55 | 53 | 9/28/2026 |
| 0.0.0-alpha.0.51 | 51 | 9/25/2026 |
| 0.0.0-alpha.0.50 | 50 | 9/25/2026 |
| 0.0.0-alpha.0.38 | 79 | 9/6/2026 |
| 0.0.0-alpha.0.37 | 66 | 9/6/2026 |