// Program.cs'te servis kaydı
services.AddMongoDbStorage("mongodb://localhost:27017");
services.AddDynamicConfiguration(
applicationName: "SERVICE-A", // Servis adı
connectionString: "mongodb://localhost:27017", // Storage bağlantısı
refreshTimerIntervalInMs: 30000 // Güncelleme aralığı (30sn)
);public class MyService
{
private readonly IConfigurationReader _configReader;
public MyService(IConfigurationReader configReader)
{
_configReader = configReader;
}
public void DoWork()
{
var siteName = _configReader.GetValue<string>("SiteName"); // "soty.io"
var timeout = _configReader.GetValue<int>("ApiTimeout"); // 30
var enabled = _configReader.GetValue<bool>("IsFeatureEnabled"); // true
var ratio = _configReader.GetValue<double>("RetryMultiplier"); // 1.5
// Artık appsettings.json'a gerek yok
}
}// ESKİ YÖNTEM (Statik - Restart Gerekli)
var timeout = int.Parse(configuration["ApiTimeout"]); // appsettings.json'dan
// YENİ YÖNTEM (Dinamik - Restart Yok)
var timeout = configReader.GetValue<int>("ApiTimeout"); // MongoDB'den dinamikdocker-compose up - Web Yönetim Paneli: http://localhost:5001
- REST API: http://localhost:5002
- API Dokümantasyonu: http://localhost:5002/swagger
- MongoDB: localhost:27017
# Servis loglarını izleme icin
docker-compose logs -f sample-service-a sample-service-b
- ✅ 3 Parametre Initialize:
ConfigurationReader(applicationName, connectionString, refreshTimerIntervalInMs)
// Thread-safe cache operasyonlari
private readonly ReaderWriterLockSlim _lock = new();
private readonly SemaphoreSlim _refreshSemaphore = new(1, 1);// docker-compose.yml'den environment değişkenleri geliyor
ApplicationName = "SERVICE-A"
// Program.cs'te kütüphane kaydetti
services.AddDynamicConfiguration("SERVICE-A", connectionString, 30000);// MongoDB'den sadece SERVICE-A + IsActive=1 veriler çekildi
var filter = Builders<ConfigurationEntry>.Filter.And(
Builders<ConfigurationEntry>.Filter.Eq(x => x.ApplicationName, "SERVICE-A"),
Builders<ConfigurationEntry>.Filter.Eq(x => x.IsActive, true)
);// Cache'e yüklenir (sadece SERVICE-A verileri)
_cache.SetConfigurations(configurations);
// 30 saniyede bir otomatik güncelleme
_refreshTimer = new Timer(RefreshConfigurationsAsync, null, 30000, 30000);// GetValue çağrıldığında cache'den döndü
var siteName = configReader.GetValue<string>("SiteName"); 🔗 Hızlı Başlangıç: docker-compose up -d → http://localhost:5001