<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alperen Sürücü on Medium]]></title>
        <description><![CDATA[Stories by Alperen Sürücü on Medium]]></description>
        <link>https://medium.com/@alperensurucu.eng?source=rss-6c57ca9f2384------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tx_ca5Uge4Q-NO6zcjQ0KA.jpeg</url>
            <title>Stories by Alperen Sürücü on Medium</title>
            <link>https://medium.com/@alperensurucu.eng?source=rss-6c57ca9f2384------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 05:43:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alperensurucu.eng/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[C# ile Creational Design Patterns]]></title>
            <link>https://medium.com/@alperensurucu.eng/c-ile-creational-design-patterns-a39a9b56f7c5?source=rss-6c57ca9f2384------2</link>
            <guid isPermaLink="false">https://medium.com/p/a39a9b56f7c5</guid>
            <category><![CDATA[oop-patterns]]></category>
            <category><![CDATA[creational-patterns]]></category>
            <category><![CDATA[singleton-multiton]]></category>
            <category><![CDATA[software-design-patterns]]></category>
            <dc:creator><![CDATA[Alperen Sürücü]]></dc:creator>
            <pubDate>Sat, 14 Mar 2026 14:36:06 GMT</pubDate>
            <atom:updated>2026-03-14T14:36:06.168Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>C# ile Creational Design Patterns</strong></p><p><em>Singleton&#39;dan Multiton&#39;a Kapsamlı Bir Rehber</em></p><p>GitHub: <a href="https://github.com/alperensurucu/Creational_Patterns">github.com/alperensurucu/Creational_Patterns</a></p><h3>Giriş: Creational Design Patterns Nedir?</h3><p>Yazılım geliştirme dünyasında, nesne oluşturma süreçleri çoğu zaman göründüğünden çok daha karmaşık bir hal alabilir. Bir nesnenin ne zaman, nasıl ve kaç kez oluşturulacağı, uygulamanın hem performansını hem de bakım kolaylığını doğrudan etkiler.</p><p>Creational Design Patterns (Yaratıcı Tasarım Desenleri), bu nesne oluşturma süreçlerini soyutlayarak daha esnek, yeniden kullanılabilir ve test edilebilir sistemler tasarlamamızı sağlar. Gang of Four (GoF) tarafından tanımlanan bu desenlerin başlıcaları şunlardır:</p><ul><li>Singleton – Bir sınıftan yalnızca tek bir örnek</li><li>Multiton – Anahtar bazlı kontrollü çoklu örnekler</li><li>Builder – Adım adım karmaşık nesneler</li><li>Factory Method – Alt sınıflara bırakılan nesne üretimi</li><li>Abstract Factory – İlişkili nesne ailelerinin üretimi</li><li>Object Pool – Nesne havuzundan yeniden kullanım</li></ul><p>Bu makalede, GitHub repomda uyguladığım Singleton ve Multiton pattern&#39;larını derinlemesine inceleyeceğiz. Örnekler C# ve ASP.NET Core üzerinde geliştirilmiştir.</p><h3>1. Singleton Design Pattern</h3><h3>Nedir?</h3><p>Singleton, bir sınıfın uygulama yaşam döngüsü boyunca yalnızca bir kez örneklenmesini garantileyen, bu tek örneğe global bir erişim noktası sunan bir tasarım desenidir.</p><h3>Ne Zaman Kullanılır?</h3><ul><li>Konfigürasyon yönetimi (appsettings, environment configs)</li><li>Loglama servisleri — tüm modüllerin aynı logger&#39;ı kullanması</li><li>Veritabanı bağlantı havuzu yönetimi</li><li>Cache mekanizmaları</li><li>Thread pool yönetimi</li></ul><h3>1.1 — Temel Singleton Implementasyonu (C#)</h3><p>En basit haliyle bir Singleton sınıfı şu bileşenlerden oluşur:</p><ul><li>private constructor → Dışarıdan new ile nesne oluşturmayı engeller</li><li>static ve private instance alanı → Tek örneği saklar</li><li>static GetInstance() metodu → Tek erişim noktasını sağlar</li></ul><pre>public class Singleton<br>{<br>private static Singleton _instance;<br>// Private constructor: dışarıdan new Singleton() yapılamaz<br>private Singleton() { }<br>public static Singleton GetInstance()<br>{<br>if (_instance == null)<br>{<br>_instance = new Singleton();<br>}<br>return _instance;<br>}<br>public void DoWork(string message)<br>{<br>Console.WriteLine($&quot;[Singleton] Çalışıyor: {message}&quot;);<br>}<br>}</pre><p>Kullanımı:</p><pre>var s1 = Singleton.GetInstance();<br>var s2 = Singleton.GetInstance();</pre><p>Console.WriteLine(object.ReferenceEquals(s1, s2)); // True — aynı nesne!</p><p><em>⚠️ Dikkat: Bu implementasyon thread-safe değildir. Çok sayıda thread eş zamanlı olarak GetInstance() metodunu çağırırsa, birden fazla nesne oluşabilir.</em></p><h3>1.2 — Thread-Safe Singleton: Double-Checked Locking</h3><p>Çok iş parçacıklı ortamlarda güvenli bir Singleton için lock kullanılır. Her çağrıda kilitleme performans kaybına yol açar. Bunu önlemek için Double-Checked Locking tekniği kullanılır:</p><pre>public class ThreadSafeSingleton<br>{<br>private static ThreadSafeSingleton _instance;<br>private static readonly object _lockObject = new object();<br>private ThreadSafeSingleton() { }<br>public static ThreadSafeSingleton GetInstance()<br>{<br>// İlk kontrol: lock almadan hızlı kontrol<br>if (_instance == null)<br>{<br>lock (_lockObject)<br>{<br>// İkinci kontrol: lock içinde kesinleştirme<br>if (_instance == null)<br>{<br>_instance = new ThreadSafeSingleton();<br>}<br>}<br>}<br>return _instance;<br>}<br>}</pre><p>volatile anahtar kelimesi ekleyerek daha güvenli hale getirilebilir:</p><p>private static volatile ThreadSafeSingleton _instance;</p><p><em>volatile, derleyicinin ve CPU&#39;nun bu alanı önbelleğe almasını veya yeniden sıralamasını önler. Özellikle güçlü bellek modeli gerektiren durumlarda kritik öneme sahiptir.</em></p><h3>1.3 — Lazy&lt;T&gt; ile Modern Singleton</h3><p>.NET&#39;in sunduğu Lazy&lt;T&gt; sınıfı, Singleton implementasyonunu çok daha temiz ve thread-safe hale getirir:</p><pre>public class LazySingleton<br>{<br>private static readonly Lazy&lt;LazySingleton&gt; _instance =<br>new Lazy&lt;LazySingleton&gt;(() =&gt; new LazySingleton());<br>private LazySingleton() { }<br>public static LazySingleton Instance =&gt; _instance.Value;<br>public string GetStatus() =&gt; &quot;LazySingleton hazır.&quot;;<br>}</pre><p><em>Lazy&lt;T&gt;, nesneyi yalnızca ilk erişimde oluşturur (lazy initialization) ve thread-safety&#39;yi otomatik olarak yönetir. Bu yaklaşım, modern C# projelerinde en çok önerilen Singleton implementasyonudur.</em></p><h3>1.4 — Asenkron Singleton (Async Singleton)</h3><p>Bazı senaryolarda Singleton nesnesinin oluşturulması asenkron bir işlem gerektirebilir: veritabanı bağlantısı kurma, dosyadan konfigürasyon yükleme, uzak API&#39;den veri çekme. lock anahtar kelimesi async metotlarda kullanılamaz; bu nedenle SemaphoreSlim kullanılır:</p><pre>public class AsyncSingleton<br>{<br>private static AsyncSingleton _instance;<br>private static readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);<br>private string _configData;<br>private AsyncSingleton(string configData)<br>{<br>_configData = configData;<br>}<br>public static async Task&lt;AsyncSingleton&gt; GetInstanceAsync()<br>{<br>if (_instance != null) return _instance;<br>await _semaphore.WaitAsync();<br>try<br>{<br>if (_instance == null)<br>{<br>var config = await LoadConfigAsync();<br>_instance = new AsyncSingleton(config);<br>}<br>}<br>finally<br>{<br>_semaphore.Release();<br>}<br>return _instance;<br>}<br>private static async Task&lt;string&gt; LoadConfigAsync()<br>{<br>await Task.Delay(100); // Simüle edilmiş asenkron işlem<br>return &quot;Config verisi yüklendi.&quot;;<br>}<br>public string GetConfig() =&gt; _configData;<br>}</pre><p>Kullanımı:</p><pre>var singleton = await AsyncSingleton.GetInstanceAsync();<br>Console.WriteLine(singleton.GetConfig());</pre><h3>1.5 — ASP.NET Core&#39;da Singleton</h3><p>ASP.NET Core, Dependency Injection (DI) altyapısıyla Singleton yönetimini tamamen framework&#39;e bırakmamıza olanak tanır. AddSingleton kaydı yeterlidir:</p><pre>// Servis arayüzü<br>public interface ICounterService<br>{<br>int Increment();<br>int GetCount();<br>}<br>// Implementasyon<br>public class CounterService : ICounterService<br>{<br>private int _count = 0;<br>public int Increment() =&gt; ++_count;<br>public int GetCount() =&gt; _count;<br>}<br>// Program.cs&#39;de kayıt<br>builder.Services.AddSingleton&lt;ICounterService, CounterService&gt;();<br>// Controller&#39;da kullanım<br>[ApiController]<br>[Route(&quot;api/[controller]&quot;)]<br>public class CounterController : ControllerBase<br>{<br>private readonly ICounterService _counterService;<br>public CounterController(ICounterService counterService)<br>{<br>_counterService = counterService;<br>}<br>[HttpGet(&quot;increment&quot;)]<br>public IActionResult Increment()<br>{<br>var count = _counterService.Increment();<br>return Ok(new { Count = count });<br>}<br>}</pre><p>ASP.NET Core servis yaşam döngüsü karşılaştırması:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*vsyZEByzk1Fq3a_D5RH0wQ.png" /></figure><h3>2. Multiton Design Pattern</h3><h3>Nedir?</h3><p>Multiton, Singleton&#39;ın genişletilmiş bir versiyonudur. Singleton&#39;da tek bir nesne varken, Multiton&#39;da her anahtar (key) için tek bir nesne bulunur. Kısaca: Key → Tek Nesne ilişkisi.</p><h3>Ne Zaman Kullanılır?</h3><ul><li>Çok kiracılı (multi-tenant) uygulamalar — Her tenant için ayrı konfigürasyon nesnesi</li><li>Veritabanı bağlantı yönetimi — Her veritabanı adı için ayrı bağlantı nesnesi</li><li>Dil/lokalizasyon servisleri — Her dil için ayrı resource manager</li><li>Plugin sistemleri — Her plugin türü için tek yönetici nesne</li></ul><h3>2.1 — Temel Multiton Implementasyonu</h3><pre>public class Multiton<br>{<br>private static readonly Dictionary&lt;string, Multiton&gt; _instances<br>= new Dictionary&lt;string, Multiton&gt;();<br>private static readonly object _lock = new object();<br>private readonly string _key;<br>private Multiton(string key)<br>{<br>_key = key;<br>Console.WriteLine($&quot;[Multiton] &#39;{key}&#39; için yeni nesne oluşturuldu.&quot;);<br>}<br>public static Multiton GetInstance(string key)<br>{<br>if (!_instances.ContainsKey(key))<br>{<br>lock (_lock)<br>{<br>if (!_instances.ContainsKey(key))<br>{<br>_instances[key] = new Multiton(key);<br>}<br>}<br>}<br>return _instances[key];<br>}<br>public string GetKey() =&gt; _key;<br>public void DoWork(string message)<br>{<br>Console.WriteLine($&quot;[Multiton:{_key}] {message}&quot;);<br>}<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*n192W2Jh3VafC1cZP8Pykg.png" /></figure><p>Kullanımı ve çıktısı:</p><pre>var dbTurkey  = Multiton.GetInstance(&quot;Turkey-DB&quot;);<br>var dbGermany = Multiton.GetInstance(&quot;Germany-DB&quot;);<br>var dbTurkey2 = Multiton.GetInstance(&quot;Turkey-DB&quot;);<br>Console.WriteLine(object.ReferenceEquals(dbTurkey, dbTurkey2));  // True<br>Console.WriteLine(object.ReferenceEquals(dbTurkey, dbGermany));  // False<br>dbTurkey.DoWork(&quot;Sorgu çalıştırılıyor...&quot;);<br>dbGermany.DoWork(&quot;Sorgu çalıştırılıyor...&quot;);<br>// ÇIKTI:<br>// [Multiton] &#39;Turkey-DB&#39; için yeni nesne oluşturuldu.<br>// [Multiton] &#39;Germany-DB&#39; için yeni nesne oluşturuldu.<br>// True<br>// False<br>// [Multiton:Turkey-DB] Sorgu çalıştırılıyor...<br>// [Multiton:Germany-DB] Sorgu çalıştırılıyor...</pre><h3>2.2 — Generic Multiton (Tip Güvenli Versiyon)</h3><p>Daha güçlü bir yaklaşım olarak generic Multiton, farklı türler için de aynı pattern&#39;ı kullanmamızı sağlar:</p><pre>public class Multiton&lt;TKey, TValue&gt; where TValue : class<br>{<br>private static readonly Dictionary&lt;TKey, TValue&gt; _instances<br>= new Dictionary&lt;TKey, TValue&gt;();<br>private static readonly object _lock = new object();<br>public static TValue GetOrCreate(TKey key, Func&lt;TKey, TValue&gt; factory)<br>{<br>if (!_instances.TryGetValue(key, out var instance))<br>{<br>lock (_lock)<br>{<br>if (!_instances.TryGetValue(key, out instance))<br>{<br>instance = factory(key);<br>_instances[key] = instance;<br>}<br>}<br>}<br>return instance;<br>}<br>public static bool TryRemove(TKey key) =&gt; _instances.Remove(key);<br>public static int Count =&gt; _instances.Count;<br>}</pre><p>Kullanımı:</p><pre>var conn1 = Multiton&lt;string, DatabaseConnection&gt;.GetOrCreate(<br>&quot;primary&quot;,<br>key =&gt; new DatabaseConnection(key, &quot;Server=primary;...&quot;)<br>);<br>var conn2 = Multiton&lt;string, DatabaseConnection&gt;.GetOrCreate(<br>&quot;replica&quot;,<br>key =&gt; new DatabaseConnection(key, &quot;Server=replica;...&quot;)<br>);</pre><h3>2.3 — Singleton ile Multiton Karşılaştırması</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*M_FSpjbSaSi3Jxvjde2gZw.png" /></figure><h3>3. Dikkat Edilmesi Gereken Noktalar</h3><h3>Singleton Anti-Pattern Riskleri</h3><p>Singleton, yanlış kullanıldığında ciddi sorunlara yol açabilir:</p><h3>Global State Problemi</h3><p>Singleton, uygulamanın herhangi bir yerinden değiştirilebilen global bir durum tutar. Bu, kodun test edilmesini zorlaştırır ve beklenmedik yan etkilere yol açabilir.</p><h3>Gizli Bağımlılıklar</h3><p>Constructor aracılığıyla değil, doğrudan GetInstance() çağrısıyla kullanıldığında bağımlılıklar gizlenir. Bu, Dependency Injection prensibini ihlal eder.</p><h3>Çözüm: Singleton + DI Birlikte Kullanımı</h3><p>En iyi pratik, Singleton pattern&#39;ını DI konteyneri ile birlikte kullanmaktır:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*VeD3AVxiaUKVf9dLRHnMuQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*HNG6y2ZnBY7sYS-AF321UQ.png" /></figure><p><em>DI ile Singleton kullanıldığında: nesnenin yaşam döngüsü framework tarafından yönetilir, unit testlerde mock kolayca enjekte edilebilir ve bağımlılıklar constructor üzerinden açıkça ifade edilir.</em></p><h3>4. Özet</h3><p>Bu makalede C# ekosisteminde Creational Design Patterns serisinin ilk iki desenini inceledik:</p><p><strong>Singleton: </strong>Uygulama genelinde tek bir nesnenin varlığını garanti eder. Temel, thread-safe, lazy ve async varyantlarıyla farklı senaryolara uyarlanabilir. ASP.NET Core&#39;da AddSingleton ile DI altyapısına entegre edilir.</p><p><strong>Multiton: </strong>Singleton&#39;ın anahtar tabanlı genişlemesidir. Her benzersiz key için tek bir nesne bulunur. Çok kiracılı sistemler, bağlantı yönetimi ve kategorize edilmiş kaynak yönetiminde idealdir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*as461p8uB9QzJ5caGh0zWA.png" /></figure><p><em>Serinin devam eden bölümlerinde Builder Pattern, Factory Method ve Object Pool Pattern konularını da ele alacağım. GitHub repoyu takip ederek güncel örneklere ulaşabilirsiniz.</em></p><p><em>Tüm kod örnekleri: </em><a href="https://github.com/alperensurucu/Creational_Patterns">github.com/alperensurucu/Creational_Patterns</a></p><p><em>Sorularınız ve önerileriniz için yorumlar bölümünü kullanabilirsiniz.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a39a9b56f7c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Aynı Prompt, Aynı Input… Neden Farklı Çıktılar Alıyoruz?]]></title>
            <link>https://medium.com/@alperensurucu.eng/ayn%C4%B1-prompt-ayn%C4%B1-input-neden-farkl%C4%B1-%C3%A7%C4%B1kt%C4%B1lar-al%C4%B1yoruz-c8fa586d4976?source=rss-6c57ca9f2384------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8fa586d4976</guid>
            <dc:creator><![CDATA[Alperen Sürücü]]></dc:creator>
            <pubDate>Fri, 23 Jan 2026 22:05:43 GMT</pubDate>
            <atom:updated>2026-01-23T22:05:43.120Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rXh2h10u6RJKcmvQnrWQZQ.png" /></figure><p>AI tabanlı sistemlerle çalışan herkesin en az bir kez karşılaştığı bir durum var:</p><p>Aynı prompt,<br> aynı endpoint,<br> aynı input…</p><p>Ama farklı çıktılar.</p><p>İlk refleks genelde şu oluyor:</p><blockquote><em>“Bir yerde hata mı var?”</em></blockquote><p>Çoğu zaman hayır.<br> Bu durum, <strong>LLM’lerin doğası gereği non-deterministic çalışmasından</strong> kaynaklanıyor.</p><p>Büyük dil modelleri, olasılıksal yapıları nedeniyle her çalıştırmada aynı cevabı üretmek zorunda değil. Bu da onları güçlü kıldığı kadar, üretim ortamlarında <strong>kontrol edilmesi zor</strong> hale getiriyor.</p><p>Peki çözüm ne?</p><ul><li>Daha büyük bir model mi?</li><li>Fine-tuning mi?</li><li>RAG mi?</li></ul><p>Zamanla şunu net şekilde görüyoruz:<br> <strong>Bu problem tek bir teknoloji tercihiyle çözülebilecek bir problem değil.</strong></p><p>Asıl farkı yaratan şey, kullanılan <strong>AI ürünlerinin nasıl tasarlandığı</strong>.</p><h3>Değer Nereden Geliyor?</h3><p>Bugün kullanılan başarılı AI ürünlerine baktığımızda çok net bir tablo ortaya çıkıyor:</p><blockquote><strong><em>Değer, tek bir bileşenden değil, doğru kurgulanmış sistemlerden geliyor.</em></strong></blockquote><p>Gerçek kullanımda işe yarayan yaklaşımların çoğunda ortak bir desen var:</p><ul><li><strong>RAG</strong> → Güncel, izlenebilir ve kaynaklı bilgiyle çalışmak</li><li><strong>Fine-tuning</strong> → Daha tutarlı davranış ve dil üretimi</li><li><strong>Multi-agent yapılar</strong> → Süreçleri bölmek, kontrolü dağıtmak</li><li><strong>Post-processing</strong> → Çıktıyı iş kurallarıyla doğrulamak</li></ul><p>Bu yaklaşımlar tek başına “mucize” yaratmıyor.<br> Ama birlikte kullanıldıklarında, sistemin <strong>öngörülebilirliğini ciddi şekilde artırıyorlar</strong>.</p><h3>Zeka mı, Kontrol mü?</h3><p>Elbette hedefimiz daha zeki sistemler geliştirmek.<br> Ancak gerçek hayatta asıl farkı yaratan şey:</p><blockquote><strong><em>Bu zekânın ne kadar kontrol edilebilir ve sürdürülebilir olduğu.</em></strong></blockquote><p>Daha öngörülebilir AI sistemleri kurmak için genelde tek bir “sihirli ayar” yok.<br> Bunun yerine küçük ama etkili önlemler birlikte kullanılıyor:</p><ul><li>Modelin serbestlik alanını bilinçli şekilde sınırlamak</li><li>Çıktıyı belirli formatlara yönlendirmek</li><li>Cevabı kaynağıyla birlikte üretmek</li><li>Çıktıyı birden fazla katmanda doğrulamak</li></ul><p>Bu yaklaşımlar, özellikle production ortamlarında <strong>riskleri azaltan kritik adımlar</strong>.</p><h3>Görmezden Gelinemeyen Gerçek: Maliyet</h3><p>Burada önemli bir denge var.</p><p>Her ek kontrol mekanizması:</p><ul><li>Daha fazla hesaplama gücü</li><li>Daha yüksek enerji ihtiyacı</li><li>Daha fazla operasyonel maliyet</li></ul><p>demek.</p><p>Bazı durumlarda bir süreci tamamen AI tabanlı otomasyona taşımaya çalışmak, beklenen faydanın çok üzerinde bir operasyonel yük oluşturabiliyor.<br> Bu yüzden “yapabiliyor muyuz?” sorusu kadar,<br> <strong>“yapmalı mıyız?”</strong> sorusu da önemli.</p><h3>Son Soru</h3><p>AI ürünleri geliştirirken asıl mesele daha büyük modeller değil,<br> <strong>daha iyi tasarlanmış sistemler</strong>.</p><p>Peki siz, kullandığınız AI ürünlerinde<br> <strong>kontrol ve maliyet dengesini nerede kuruyorsunuz?</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8fa586d4976" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Entity Framework and how is it used?]]></title>
            <link>https://medium.com/@alperensurucu.eng/what-is-entity-framework-and-how-is-it-used-0e544bdf8c32?source=rss-6c57ca9f2384------2</link>
            <guid isPermaLink="false">https://medium.com/p/0e544bdf8c32</guid>
            <dc:creator><![CDATA[Alperen Sürücü]]></dc:creator>
            <pubDate>Wed, 17 Jul 2024 14:13:55 GMT</pubDate>
            <atom:updated>2024-07-17T14:13:55.326Z</atom:updated>
            <content:encoded><![CDATA[<ul><li>Entity Framework is an ORM (Object-Relational Mapping) tool that helps applications manage database operations.</li><li><strong>We create tables and such within the project through migration operations.</strong></li><li>Migration operations allow us to define database changes (such as creating new tables or adding columns to existing tables) in code using Entity Framework.</li><li><strong>We will perform operations such as adding, deleting, updating, and listing records.</strong></li><li>Using Entity Framework, we can perform operations such as adding, deleting, updating, and listing records in the database.</li><li><strong>We will explore navigating relational data using Navigation Property operations.</strong></li><li>Navigation Property operations in Entity Framework allow us to navigate through relational data.</li><li><strong>Entity Framework is → Mapping data from database tables to entity classes in the application.</strong></li><li>Entity Framework maps data from database tables to entity classes in the application.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RhTarSH1YiFuk5mKOe5VDA.png" /></figure><ul><li><strong>I’m using SQLite for Entity Framework.</strong></li><li><strong>Write in the terminal →</strong> dotnet add package Microsoft.EntityFrameworkCore.Sqlite --version 7.0.8</li><li>You can see it here once it’s installed in the terminal.</li></ul><h3><strong><em>“Notes from the training I received from Sadık Turan</em></strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gs4f2mmg9947JU8zO0VBoQ.png" /></figure><p>We created a folder named Data. Inside this, we created our Entity classes.</p><p>Now, we will create a DBContext to turn these classes into tables in the database.</p><p>We are using the code-first approach.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*-KTLToxDOVnAXE-DHn7hmw.png" /></figure><p>In the Program.cs file, we notify the existence of the DbContext. For this, we add a service.</p><pre>builder.Services.AddDbContext&lt;DataContext&gt;(options =&gt;<br>{<br>    options.UseSqlite();<br>});</pre><p>After adding this to the appsettings.Development.json file, the code in builder.services changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*hXpBfZjdxjvVKqGbEkVKkA.png" /></figure><p>“Let’s write the new code for builder.Services in Program.cs after appsetting.development.json.&quot;</p><pre><br>builder.Services.AddDbContext&lt;DataContext&gt;(options =&gt;<br>{<br>    var config = builder.Configuration;<br>    var connectionString = config.GetConnectionString(&quot;dataabse&quot;);<br>    <br>    options.UseSqlite(connectionString);<br>});</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*Edi0mNOKyAgAYIk1MuHq9Q.png" /></figure><p>“After this point, everything is ready for it to become a physical database; we achieve this transformation into a physical database using Migration operations.”</p><p><strong>&quot;The codes to be written in the terminal&quot;</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*fi6LGFyp7o0ZtcsxGWUZiA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*5Zk01wzYsgMOyOJhcnB8LQ.png" /></figure><p>“Now we need to install the design package.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*E8HIhV5Xl8puQLB5wH2BQw.png" /></figure><p>Before entering the code below in the terminal, there is a code that needs to be added; otherwise, an error occurs. We manually provide DbContext options because it cannot obtain the information on its own.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*KqsEmuyjdWZ28RBDTXizJA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*Xb8A1e8Z9P8zbI3lp7yyAA.png" /></figure><p>“In our last update, we should have added a folder named ‘Migration’. (InitialCreate is an optional name.)”</p><p>“As a result of this process, a folder named ‘mydb.db’ was created. To open it, you’ll need to download SQLite Browser.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*XmlRpvyATxfhmb1mkRYJFg.png" /></figure><p><a href="https://sqlitebrowser.org/dl/">https://sqlitebrowser.org/dl/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w2Vv6cqJs4_AefFbMlBoLg.png" /></figure><p>“As seen above, entity, database connections, and designs are ready up to this point. From now on, the focus will be on the saving process.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*G6OOEun7rgKRd9UL0hzliw.png" /></figure><p>Added. Then transferring to the main page.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*xkbQD5DZhsn-ANbeqx2oQw.png" /></figure><p>“List the students in the database.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*e0RmW3e79i4DOmPbakdAHg.png" /></figure><p>“We wrote a .cshtml page in the View/Ogrenci/Index folder. We outlined the layout for the list to be displayed inside.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*iNyUtzsKKNZUcfBdRs4ArQ.png" /></figure><p>Listed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CdeBJXMxiAvxFoE9UtWRNQ.png" /></figure><p>“I’ll try to explain how we perform the <em>Delete</em> operation:<br>When you click <em>Delete</em> next to a listed item, it asks if you want to delete it. If you select ‘No’, it redirects you back to the Index, the list. If you select ‘Yes’, it updates and then shows the updated list.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*ylrY2v5E_02_QavIUL7rGQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*aVbbIBGlSqrsS6oCYIZ2Zw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*QizrlQCfXTc9ZkgluS1q0Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0e544bdf8c32" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating an ASP.NET Core Web API Project with MySQL Using Entity Framework Core in .NET 7.0]]></title>
            <link>https://medium.com/@alperensurucu.eng/creating-an-asp-net-core-web-api-project-with-mysql-using-entity-framework-core-in-net-7-0-a9152291c5dd?source=rss-6c57ca9f2384------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9152291c5dd</guid>
            <dc:creator><![CDATA[Alperen Sürücü]]></dc:creator>
            <pubDate>Wed, 17 Jul 2024 13:16:17 GMT</pubDate>
            <atom:updated>2024-07-17T13:16:17.885Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5470U1JbtvhDL7lTRa-qBA.jpeg" /></figure><h3>Creating an ASP.NET Core Web API Project with MySQL Using Entity Framework Core in .NET 7.0</h3><p>In this article, we’ll walk through creating a Web API project using .NET 7.0 and ASP.NET Core, integrating it with MySQL database using Entity Framework Core step by step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*LoGp93TN1L106NPHJmoYzA.jpeg" /></figure><h4>Creating the Project</h4><p>To start off, we create a new ASP.NET Core Web API project with the following .csproj file:</p><pre>&lt;Project Sdk=&quot;Microsoft.NET.Sdk.Web&quot;&gt;<br><br>  &lt;PropertyGroup&gt;<br>    &lt;TargetFramework&gt;net7.0&lt;/TargetFramework&gt;<br>    &lt;Nullable&gt;enable&lt;/Nullable&gt;<br>    &lt;ImplicitUsings&gt;enable&lt;/ImplicitUsings&gt;<br>  &lt;/PropertyGroup&gt;<br><br>  &lt;ItemGroup&gt;<br>    &lt;PackageReference Include=&quot;Microsoft.AspNetCore.OpenApi&quot; Version=&quot;7.0.14&quot; /&gt;<br>    &lt;PackageReference Include=&quot;Microsoft.EntityFrameworkCore&quot; Version=&quot;7.0.7&quot; /&gt;<br>    &lt;PackageReference Include=&quot;Microsoft.EntityFrameworkCore.Tools&quot; Version=&quot;7.0.7&quot;&gt;<br>      &lt;PrivateAssets&gt;all&lt;/PrivateAssets&gt;<br>      &lt;IncludeAssets&gt;runtime; build; native; contentfiles; analyzers; buildtransitive&lt;/IncludeAssets&gt;<br>    &lt;/PackageReference&gt;<br>    &lt;PackageReference Include=&quot;Pomelo.EntityFrameworkCore.MySql&quot; Version=&quot;7.0.0&quot; /&gt;<br>    &lt;PackageReference Include=&quot;Swashbuckle.AspNetCore&quot; Version=&quot;6.5.0&quot; /&gt;<br>  &lt;/ItemGroup&gt;<br><br>&lt;/Project&gt;</pre><p>This file defines our project’s target framework and includes necessary package references for Entity Framework Core and MySQL integration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*5bEVW_M3mBtyI59guQGq_w.png" /></figure><h4>Database Connection and Model Creation</h4><p>We define our database connection and model using the AppDbContext class and Product model:</p><pre>namespace EntityFrameworkCore.MySQL.Data<br>{<br>    public class AppDbContext : DbContext<br>    {<br>        public AppDbContext(DbContextOptions&lt;AppDbContext&gt; options) : base(options) { }<br>        public DbSet&lt;Product&gt; Products { get; set; }<br>    }<br>}<br><br>namespace EntityFrameworkCore.MySQL.Models<br>{<br>    public class Product<br>    {<br>        public int Id { get; set; }<br>        public string Name { get; set; }<br>        public string Type { get; set; }<br>    }<br>}</pre><p>The AppDbContext class inherits from DbContext and provides access to the Products table through the Product model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*388nhiTkr2TiKWP0NLS2HA.png" /></figure><h4>Creating Controllers</h4><p>We manage API operations by creating a ProductsController:</p><pre>using EntityFrameworkCore.MySQL.Data;<br>using Microsoft.AspNetCore.Mvc;<br><br>namespace EntityFrameworkCore.MySQL.Controllers<br>{<br>    [Route(&quot;api/[controller]&quot;)]<br>    [ApiController]<br>    public class ProductsController : ControllerBase<br>    {<br>        private readonly AppDbContext _appDbContext;<br>        <br>        public ProductsController(AppDbContext appDbContext)<br>        {<br>            _appDbContext = appDbContext;<br>        }<br><br>        // CRUD operations can be defined here.<br>    }<br>}</pre><h4>Database Connection Settings</h4><p>Database connection settings are stored in appsettings.json and managed within the project:</p><pre>{<br>  &quot;Logging&quot;: {<br>    &quot;LogLevel&quot;: {<br>      &quot;Default&quot;: &quot;Information&quot;,<br>      &quot;Microsoft.AspNetCore&quot;: &quot;Warning&quot;<br>    }<br>  },<br>  &quot;AllowedHosts&quot;: &quot;*&quot;,<br>  &quot;ConnectionStrings&quot;: {<br>    &quot;AppConnectionString&quot;: &quot;Server=22.333.333.22;Database=alperen_Db;User=alperen_user;Password=alperen_password;&quot;<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*INE1o_q_FKNyp9X7uH0yaw.png" /></figure><h4>Service Management and Swagger Integration</h4><p>We initialize required services and enable Swagger/OpenAPI support for API documentation:</p><pre>var builder = WebApplication.CreateBuilder(args);<br><br>builder.Services.AddControllers();<br>builder.Services.AddEndpointsApiExplorer();<br>builder.Services.AddSwaggerGen();<br><br>var connectionString = builder.Configuration.GetConnectionString(&quot;AppConnectionString&quot;);<br>builder.Services.AddDbContext&lt;AppDbContext&gt;(options =&gt; options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)));<br><br>var app = builder.Build();<br><br>if (app.Environment.IsDevelopment())<br>{<br>    app.UseSwagger();<br>    app.UseSwaggerUI();<br>}<br><br>app.UseHttpsRedirection();<br>app.UseAuthorization();<br>app.MapControllers();<br>app.Run();</pre><p>In this code block, AddDbContext configures the MySQL database connection, and UseSwagger enables Swagger UI for API documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*c-jriQfFsukeSnsCsKUt3g.png" /></figure><h4>Conclusion</h4><p>In this article, we’ve covered the process of creating an ASP.NET Core Web API project using .NET 7.0 and integrating it with MySQL using Entity Framework Core. You’ve learned about the project file, model definitions, controllers, and database connection settings necessary for ASP.NET Core applications using MySQL. These steps provide a foundational understanding for building and managing database operations in an API project.<br>ASP.NET Core Web API with MySQL: Key Learnings</p><ul><li><strong>Project Setup</strong>: We mastered setting up a .NET 7.0 project as an ASP.NET Core Web API, configuring essential packages like Microsoft.EntityFrameworkCore and Pomelo.EntityFrameworkCore.MySql.</li><li><strong>Database Integration</strong>: Integrated MySQL seamlessly using Entity Framework Core (EF Core), enabling efficient data modeling and interaction via DbContext.</li><li><strong>API Endpoint Management</strong>: Learned to create and manage API endpoints (ProductsController) for CRUD operations, enhancing our ability to handle HTTP requests and responses.</li><li><strong>Dependency Injection</strong>: Leveraged ASP.NET Core’s dependency injection (DI) for efficient service management, particularly in configuring and utilizing database connections (AddDbContext).</li><li><strong>Documentation with Swagger</strong>: Implemented Swagger (Swashbuckle) for API documentation, enhancing project visibility and developer experience.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9152291c5dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Nesne Yönelimli Programlamanın Temel Taşları: S.O.L.I.D İlkeleri]]></title>
            <link>https://medium.com/@alperensurucu.eng/nesne-y%C3%B6nelimli-programlaman%C4%B1n-temel-ta%C5%9Flar%C4%B1-s-o-l-i-d-i%CC%87lkeleri-55d6953f7aa6?source=rss-6c57ca9f2384------2</link>
            <guid isPermaLink="false">https://medium.com/p/55d6953f7aa6</guid>
            <dc:creator><![CDATA[Alperen Sürücü]]></dc:creator>
            <pubDate>Fri, 12 Jan 2024 03:12:23 GMT</pubDate>
            <atom:updated>2024-01-12T03:15:14.956Z</atom:updated>
            <content:encoded><![CDATA[<h3>S.O.L.I.D — Nesne Yönelimli Programlamanın Temel Taşları</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*pnyxRM7Gi6G_j8CzeRXc9g.png" /></figure><p>Eğer nesne tabanlı programlamayla ilgileniyorsanız, muhtemelen SOLID prensiplerini duymuşsunuzdur. Bu prensipler, yazılım geliştirme süreçlerini daha ölçeklenebilir ve bakımı kolay hale getirmek için öne sürülmüştür. Yani, projeniz büyüdükçe yeni özellikler eklemek daha kolay olacak ve kodunuzu güncellemek daha az karmaşık hale gelecektir.</p><p>SOLID prensiplerini uygulamak, kodunuzu daha esnek ve yönetilebilir hale getirecek, aynı zamanda kod tekrarını ve sürekli metot değişikliklerini minimumda tutacaktır. Yani, kodunuz daha anlaşılır olacak ve projenizin gelişmesi daha sorunsuz olacaktır.</p><blockquote><strong>S.O.L.I.D Prensiplerinden Biraz Daha Ayrıntılı Bahsedelim mi ?</strong></blockquote><h4>=&gt; S.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_1UgOJ0Cptt-15lR-r0l9Q.jpeg" /></figure><p>Tek Sorumluluk Prensibi dediğimiz şey aslında şu: her sınıfın hayatında yalnızca bir işi olmalı. Yani bir sınıf, kendisine verilen görevi yerine getirirken başka sınıfların ya da metodların işine karışmamalı. Bu yaklaşım, kodunuzu değiştirmeniz gerektiğinde nelerin etkileneceğini daha rahat anlamanızı sağlar. Elbette uygulamanızın ihtiyaçları zamanla değişebilir. Bu değişen ihtiyaçlar, size yeni talepler olarak gelebilir ve kodunuzu geliştirmeniz ya da değiştirmeniz gerekebilir.</p><p>Gereksinimler değiştikçe ve kodu yeniden düzenlemeniz gerektiğinde, sınıflar da bu durumdan etkilenecek. Bir sınıfın üzerinde ne kadar fazla sorumluluk varsa, o sınıfı değiştirmek o kadar zorlaşır. Çünkü artan sorumluluklar, diğer görevleri etkileme olasılığını artırır; bu da diğer sınıflara olan bağımlılıkları tetikler ve sonuç olarak bir karışıklık ortaya çıkar.</p><h3>=&gt; O.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*JWVwUuTyaJx3krnT22vsTQ.png" /></figure><p>Açık — Kapalı Prensibi, sınıfların değişikliklere kapalı olup yeni özellikler eklenmesine ise açık olması gerektiğini savunuyor. Bir sınıfın mevcut metodunu değiştirmek, o sınıfı kullanan tüm sistemleri etkileyebilir. Eğer sınıfın daha fazla işlevselliğe ihtiyacı varsa, ideal yaklaşım mevcut metotları değiştirmek değil, mevcut yapının bütünlüğünü koruyarak yeni metotlar eklemektir. Bu, var olan sistemlerde olumsuz etkileri en aza indirir ve sınıfın yeni özelliklere sorunsuz bir şekilde adapte olmasını sağlar.</p><h3>=&gt; L.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*rm31PrA8NusV3O_d5xajHQ.jpeg" /></figure><p>Liskov’un Yerine Geçme Prensibi, kodumuzda alt sınıfları temel sınıfın yerine koyabilmemiz gerektiğini söyler, sanki bir alt sınıf ile temel sınıfın takas edilebilir gibi! Tabii ki, bu takas sırasında alt sınıflar, temel sınıfların bütün metodlarını çalmalı; aksi takdirde kodumuzda anlam veremediğimiz şeyler olabilir, ki kimse istemez böyle absürt durumlarla uğraşmayı, değil mi? 😉</p><h3>=I.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*JIrPhnWpOZeGMMu7kwZ1Jw.png" /></figure><p>Arayüzlerin Ayrımı Prensibi, sanki bir arkadaşımızın çok yetenekli olduğu halde, hepimizin onun yeteneklerini zorla kullanmaya çalışmamamız gerektiğini söylüyor. Yani, bir sınıf yalnızca ihtiyacı olan yeteneklere odaklanmalıdır; diğer yeteneklere mecbur kalmamalı. Bu prensip, interfacelerin sadece o an işimize yarayacak metotları içermesi gerektiğini savunuyor. Bir sınıf, sadece görevlerini yerine getirmek için gerekli olan metodları implement etmeli. Eğer özelleştirilmiş şekilde birden fazla interface kullanırsak, bu interfaceleri implement eden sınıfların “Tek Sorumluluk” prensibine de uymasına yardımcı oluruz.</p><p>iyelim ki bir arabayı yöneten bir arayüze (interface) ihtiyacınız var. Ancak bu arayüz, hem aracı sürme (drive) hem de müzik çalma (playMusic) yeteneklerini içeriyor. Ancak bazı sürücüler sadece sürüşle ilgileniyor ve müzik çalmakla hiç ilgilenmiyor. Bu durumda, tek bir geniş arayüz kullanmak, sadece sürüşle ilgilenen sürücülerin gereksiz müzik çalma özelliklerine sahip olmasına neden olabilir.</p><p>Interface Segregation Prensibi’ni uygularsak, bu durumu iki ayrı arayüzle ele alabiliriz : IDriveable ve IPlayable. Her iki arayüzü de kendi ihtiyaçlarına göre uygulayan sınıflar, sadece kendilerine uygun olan metotları içerir. Böylece, sadece sürüşle ilgilenen bir sürücü sadece IDriveable arayüzünü uygularken, müzikle ilgilenen bir sürücü hem IDriveable hem de IPlayable arayüzlerini uygulayabilir.</p><h3>=D.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*Nr8pDuyiodabq2Jl8LkYbQ.png" /></figure><p><em>Bağımlılığın Ters Çevrilmesi </em>prensibine göre yüksek seviyeli sınıflar, düşük seviyeli sınıflara bağlı olmamalıdır. Yani Soyutlamalar ayrıntılara bağlı olmamalıdır. Ayrıntılar soyutlamalara bağlı olmalıdır. Böylece alt sınıflarda yapılan değişiklikler üst sınıfları etkilemeyecektir.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55d6953f7aa6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>