MERSELSDK.Core.Configuration
0.1.0-preview.20260710002836
dotnet add package MERSELSDK.Core.Configuration --version 0.1.0-preview.20260710002836
NuGet\Install-Package MERSELSDK.Core.Configuration -Version 0.1.0-preview.20260710002836
<PackageReference Include="MERSELSDK.Core.Configuration" Version="0.1.0-preview.20260710002836" />
<PackageVersion Include="MERSELSDK.Core.Configuration" Version="0.1.0-preview.20260710002836" />
<PackageReference Include="MERSELSDK.Core.Configuration" />
paket add MERSELSDK.Core.Configuration --version 0.1.0-preview.20260710002836
#r "nuget: MERSELSDK.Core.Configuration, 0.1.0-preview.20260710002836"
#:package MERSELSDK.Core.Configuration@0.1.0-preview.20260710002836
#addin nuget:?package=MERSELSDK.Core.Configuration&version=0.1.0-preview.20260710002836&prerelease
#tool nuget:?package=MERSELSDK.Core.Configuration&version=0.1.0-preview.20260710002836&prerelease
MERSELSDK.Core.Configuration
Genel Bakış
MERSELSDK.Core.Configuration modülü, .NET uygulamaları için merkezi ve güvenli konfigürasyon ile gizli bilgi (secret) yönetimi sağlar. Consul ve Vault ile entegre çalışır, tenant ve servis bazlı yapılandırma sunar. Fluent API ve Builder Pattern ile kolay ve okunabilir bir kullanım sağlar.
Özellikler
- Consul ve Vault ile merkezi konfigürasyon ve secret yönetimi
- Tenant ve servis bazlı yapılandırma desteği
- Otomatik değişiklik algılama ve yeniden yükleme (reload on change)
- Ortam değişkenleriyle kolay konfigürasyon
- Fluent API ile kolay ve okunabilir kullanım
- Token otomatik yenileme desteği (Vault için)
- Opsiyonel veya zorunlu (required) ayar desteği
Kurulum
NuGet üzerinden ekleyin:
dotnet add package MERSELSDK.Core.Configuration
Gerekli ek bağımlılıklar:
- Winton.Extensions.Configuration.Consul
- VaultSharp.Extensions.Configuration
- Ardalis.GuardClauses
DI Entegrasyonu
Program.cs dosyanızda aşağıdaki gibi servisleri kaydedin:
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
builder.Services.AddConsulConfigurationBuilder(builder.Configuration, builder.Configuration);
builder.Services.AddVaultSecretBuilder(builder.Configuration, builder.Configuration);
Kullanım
Consul ile Konfigürasyon Yönetimi
var configurationBuilder = new ConfigurationBuilder();
var consulConfigBuilder = new ConsulConfigurationBuilder(configurationBuilder)
.SetHost("http://localhost:8500")
.SetServiceName("MyService")
.SetTenant("default")
.SetToken("my-consul-token")
.SetConfigurationKey("appsettings.json")
.EnableReloadOnChange();
consulConfigBuilder.Build();
var configuration = configurationBuilder.Build();
Vault ile Secret Yönetimi
var configurationBuilder = new ConfigurationBuilder();
var vaultSecretBuilder = new VaultSecretBuilder(configurationBuilder)
.SetHost("https://vault.example.com")
.SetToken("my-vault-token")
.SetServiceName("MyService")
.SetTenant("default")
.SetSecretKey("database")
.EnableReloadOnChange()
.EnableTokenAutoRenew(); // Token otomatik yenileme
vaultSecretBuilder.Build();
var configuration = configurationBuilder.Build();
Ortam Değişkenleri ile Kullanım
Aşağıdaki ortam değişkenlerini tanımlayabilirsiniz:
- Consul için:
CONSUL_HOST,SERVICE_NAME,TENANT,CONSUL_TOKEN - Vault için:
VAULT_HOST,SERVICE_NAME,TENANT,VAULT_TOKEN
var configurationBuilder = new ConfigurationBuilder();
var consulConfigBuilder = new ConsulConfigurationBuilder(configurationBuilder)
.SetConfigurationKey("appsettings.json")
.EnableReloadOnChange();
consulConfigBuilder.Build();
var configuration = configurationBuilder.Build();
Ana Sınıflar ve Arayüzler
- ConsulConfigurationBuilder: Consul ile konfigürasyon yönetimi için builder sınıfı.
- VaultSecretBuilder: Vault ile secret yönetimi için builder sınıfı.
- IConsulConfiguration: Consul konfigürasyonları için arayüz.
- IVaultSecret: Vault secretları için arayüz.
- ConsulConfigurationManagerOptions: Consul yapılandırma seçenekleri.
- VaultSecretManagerOptions: Vault yapılandırma seçenekleri.
Gelişmiş Özellikler
- Token Otomatik Yenileme: Vault token'ınızın süresi dolmadan otomatik olarak yenilenmesini sağlayabilirsiniz.
- Opsiyonel Konfigürasyon: Konfigürasyonun opsiyonel veya zorunlu olup olmadığını belirleyebilirsiniz.
- Multi-Tenant Desteği: Her tenant için ayrı konfigürasyon ve secret yönetimi.
Örnek Proje Kullanımı
DI Container'da Vault Secrets Ayarlaması
Aşağıdaki extension metodu kullanarak Vault secretlarını kolayca ayarlayabilirsiniz:
public static void AddVaultSecrets(this IServiceCollection services, IConfiguration configuration, IConfigurationBuilder configurationBuilder, string environment)
{
services.AddVaultSecretBuilder(configuration, configurationBuilder);
var vaultSecretBuilder = services.BuildServiceProvider().GetService<VaultSecretBuilder>();
//Vault'un tokeninin otomatik yenilenmesi ayarı
vaultSecretBuilder.EnableTokenAutoRenew();
vaultSecretBuilder.SetSecretKey("elastic-apm").Build();
}
Kullanım: Program.cs veya DependecyInjection.cs dosyanızda bu extension'ı çağırın:
builder.Services.AddVaultSecrets(builder.Configuration, builder.Configuration, environment);
Bu yöntem:
- Vault'tan
elastic-apmsecretını çeker - Vault token'ının otomatik yenilenme özelliğini aktif eder
- Secrecleri uygulama konfigürasyonuna ekler
Tip Bazlı Secret ve Konfigürasyon Binding
Vault: SetSecretKey ve SetSecret<T>
vaultSecretBuilder.SetSecretKey("sentry").Build();- Vault'tan
"sentry"anahtarı altındaki secret'ı çeker ve konfigürasyona ekler. - Bu yöntemle secret'ı string anahtar ile manuel olarak belirtirsin.
- Vault'tan
vaultSecretBuilder.SetSecret<StorageOptionsSecret>().Build();StorageOptionsSecretadında bir sınıfın (veya record'un) Vault'tan otomatik olarak çekilmesini sağlar.SetSecret<T>()fonksiyonu, generic tipin adını otomatik olarak Vault anahtarı olarak kullanır (örn.storage-options).- Ayrıca, ilgili secret'ı otomatik olarak DI container'a bind eder ve
IOptions<StorageOptionsSecret>olarak enjekte edilebilir hale getirir. - Bu tipin
IVaultSecretarayüzünü implemente etmesi gerekir.
Vault için tip bazlı binding örneği:
public class StorageOptionsSecret : IVaultSecret
{
public string ConnectionString { get; set; }
public string AccessKey { get; set; }
// ... diğer secret alanları
}
// Kullanım:
vaultSecretBuilder.SetSecret<StorageOptionsSecret>().Build();
// Artık IOptions<StorageOptionsSecret> ile tip güvenli olarak erişebilirsin.
Consul: SetConfigurationKey ve SetConfiguration<T>
consulConfigurationBuilder.SetConfigurationKey("mersel-sdk").Build();- Consul'dan
"mersel-sdk"anahtarı altındaki konfigürasyonu çeker ve ekler. - Anahtar string olarak manuel verilir.
- Consul'dan
consulConfigurationBuilder.SetConfiguration<EndpointnConfiguration>().Build();EndpointnConfigurationadında bir sınıfın Consul'dan otomatik olarak çekilmesini sağlar.SetConfiguration<T>()fonksiyonu, generic tipin adını otomatik olarak Consul anahtarı olarak kullanır (örn.e-transformation-configuration).- Ayrıca, ilgili konfigürasyonu otomatik olarak DI container'a bind eder ve
IOptions<EndpointnConfiguration>olarak enjekte edilebilir hale getirir. - Bu tipin
IConsulConfigurationarayüzünü implemente etmesi gerekir.
Consul için tip bazlı binding örneği:
public class EndpointnConfiguration : IConsulConfiguration
{
public string Endpoint { get; set; }
public int Timeout { get; set; }
// ... diğer konfigürasyon alanları
}
// Kullanım:
consulConfigurationBuilder.SetConfiguration<EndpointnConfiguration>().Build();
// Artık IOptions<EndpointnConfiguration> ile tip güvenli olarak erişebilirsin.
Nasıl Çalışır?
- SetSecret<T> ve SetConfiguration<T> fonksiyonları, tip adını otomatik olarak Vault/Consul anahtarı olarak kullanır (Kebab-case'e çevirir).
- Ayrıca, ilgili tipin konfigürasyonunu/secret'ını DI container'a
IOptions<T>olarak ekler. - Bu sayede, uygulamanın herhangi bir yerinde tip güvenli olarak
IOptions<T>ile erişim sağlanır. - Eğer farklı bir anahtar veya farklı bir section kullanılacaksa, overload'lar ile bu özelleştirilebilir:
SetSecret<T>(string secretKey)SetSecret<T>(string secretKey, string section)SetConfiguration<T>(string consulKey)SetConfiguration<T>(string consulKey, string section)
Tip Bazlı Kullanım
Vault için:
// Secret'ı doğrudan anahtar ile ekleme:
vaultSecretBuilder.SetSecretKey("sentry").Build();
// Tip bazlı secret binding:
vaultSecretBuilder.SetSecret<StorageOptionsSecret>().Build();
// Artık IOptions<StorageOptionsSecret> ile tip güvenli olarak erişebilirsin.
Consul için:
// Konfigürasyonu doğrudan anahtar ile ekleme:
consulConfigurationBuilder.SetConfigurationKey("mersel-sdk").Build();
// Tip bazlı konfigürasyon binding:
consulConfigurationBuilder.SetConfiguration<EndpointnConfiguration>().Build();
// Artık IOptions<EndpointnConfiguration> ile tip güvenli olarak erişebilirsin.
Not: Tip bazlı binding için ilgili tiplerin
IVaultSecretveyaIConsulConfigurationarayüzünü implemente etmesi gerekir.
Katkıda Bulunma
Katkı sağlamak için issue veya pull request açabilirsiniz.
Lisans
MIT Lisansı ile lisanslanmıştır.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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 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. |
-
net6.0
- Ardalis.GuardClauses (>= 5.0.0)
- MERSELSDK.Core.Extensions (>= 0.1.0-preview.20260710002836)
- Microsoft.Extensions.Configuration (>= 6.0.2)
- Microsoft.Extensions.DependencyInjection (>= 6.0.2)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 6.0.1)
- VaultSharp.Extensions.Configuration (>= 1.0.5)
- Winton.Extensions.Configuration.Consul (>= 3.4.0)
-
net9.0
- Ardalis.GuardClauses (>= 5.0.0)
- MERSELSDK.Core.Extensions (>= 0.1.0-preview.20260710002836)
- Microsoft.Extensions.Configuration (>= 9.0.0)
- Microsoft.Extensions.DependencyInjection (>= 9.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.0)
- VaultSharp.Extensions.Configuration (>= 1.0.5)
- Winton.Extensions.Configuration.Consul (>= 3.4.0)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on MERSELSDK.Core.Configuration:
| Package | Downloads |
|---|---|
|
MERSELSDK.Core.StorageService
Package Description |
|
|
MERSELSDK.ETransformation.Gib.Services
Package Description |
|
|
MERSELSDK.Core
Package Description |
|
|
MERSELSDK.Caching
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-preview.20260710002836 | 122 | 7/10/2026 |
| 0.1.0-preview.20260709234905 | 88 | 7/9/2026 |
| 0.1.0-preview.20260702055213 | 125 | 7/2/2026 |
| 0.0.1-preview.20260627.112114 | 77 | 6/27/2026 |
| 0.0.1-preview.20260627.110256 | 91 | 6/27/2026 |