<?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 Hakan Karabulut on Medium]]></title>
        <description><![CDATA[Stories by Hakan Karabulut on Medium]]></description>
        <link>https://medium.com/@karabuluthakan?source=rss-e3ddd311faec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pxORYTu2G5mrN8zLyjW3XQ.jpeg</url>
            <title>Stories by Hakan Karabulut on Medium</title>
            <link>https://medium.com/@karabuluthakan?source=rss-e3ddd311faec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 20:14:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@karabuluthakan/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[“Başçıvan Mikro Servisler” : Spagetti Mimari ve AI Çağında Çöpe Atılan Token’lar]]></title>
            <link>https://medium.com/devopsturkiye/ba%C5%9F%C3%A7%C4%B1van-mikro-servisler-spagetti-mimari-ve-ai-%C3%A7a%C4%9F%C4%B1nda-%C3%A7%C3%B6pe-at%C4%B1lan-tokenlar-5454266ac4b1?source=rss-e3ddd311faec------2</link>
            <guid isPermaLink="false">https://medium.com/p/5454266ac4b1</guid>
            <category><![CDATA[software-design]]></category>
            <category><![CDATA[microservice-architecture]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <category><![CDATA[technical-debt]]></category>
            <dc:creator><![CDATA[Hakan Karabulut]]></dc:creator>
            <pubDate>Wed, 15 Apr 2026 12:48:06 GMT</pubDate>
            <atom:updated>2026-04-16T09:38:05.227Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*plsQb_sO_SbNyrpfpp7_Pw.png" /></figure><p>Başlıktaki “Başçıvan” bir yazım yanlışı değil. G.O.R.A. filmindeki o meşhur sahneyi hatırlarsınız; “Aşçı bahçıvana, bahçıvan şoföre, sonra hepsi uşağa…”. “Başçıvan” bu meşhur sahneye ve tasarım hatası mikro servislere yaptığım bilinçli bir gönderme.</p><p>Yapay zeka araçları hayatımıza girmeden önce en büyük gündemimiz “mikro servis dönüşümleriydi”. Hakkını teslim edelim; sınırları Domain Driven Design (DDD) ile doğru çizilmiş, Bounded Context (Sınırlandırılmış Bağlam) kavramı gerçekten içselleştirilmiş bir mikro servis mimarisi elbette hayat kurtarır. Gerçekçi olalım, bugün piyasada “mikro servis” etiketiyle dolaşan projelerin çoğunluğu, o masadaki yeri hak etmiyor. <a href="https://mis.sadievrenseker.com/2015/01/conway-yasasi-conways-law/">Conway Yasası</a>’nı unuttuk; mikro servislerin sadece kodu değil, <strong>büyük ekipleri</strong> de ölçeklendirmek için olduğunu göz ardı ettik.</p><p>Özgeçmişlerde (CV) şık dursun diye, <a href="https://www.youtube.com/watch?v=BGFI3pomQYc&amp;t=22s">“Resume Driven Development”</a> (Özgeçmiş Şişirme Odaklı Geliştirme) kafasıyla her şeyin lime lime edildiği senaryolarda, sistemler birer mutanta dönüşüyor. Amacım o klasik “Monolit vs Mikro servis” tartışmasını yeniden alevlendirmek değil. Benim derdim, zamanında verilen yanlış mimari kararların bugün başımıza nasıl yeni bir bela açtığıyla ilgili: AI asistanlarında çöpe attığımız token’lar ve context window (bağlam penceresi) israfı.</p><p><strong>Aşçı Bahçıvana, Bahçıvan Şoföre: Mimari Çöküşün Anatomisi</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m6lVPpiKErOImidlOxX-Fw.png" /><figcaption>“BAŞÇIVAN” MİKROSERVİS ANATOMİSİ</figcaption></figure><p>Süslü sunumlarda “CQRS ve Event-Driven mikro servis mimarisi kurduk” denir. Ama gerçek dünyada kod can çekişiyordur. Gelin bu “Başçıvan” mimarisinin anatomisine yakından bakalım:</p><ul><li><strong>Sıkı Bağımlılık (Aşçı Bahçıvana):</strong> Sistemde bir “Aşçı” (Sipariş) ve “Bahçıvan” (Ödeme) servisimiz olsun. CQRS falan kurmuşuz güya. Ama Aşçı servisi, işini bitirmek için HTTP üzerinden senkron bir şekilde Bahçıvan’ı bekliyor. Bahçıvan çökerse Aşçı da patlıyor. Hata yönetimi (fallback) hak getire.</li><li><strong>Döngüsel Bağımlılık (Bahçıvan Şoföre):</strong> Bahçıvan tam işlem yaparken aniden “Şoför” (Kargo) servisinin durumunu merak ediyor ve ona istek atıyor. Şoför de cevap dönebilmek için dönüp Aşçı’nın verisine ihtiyaç duyuyor. Tebrikler, kuyruğunu kovalayan bir köpek sendromu yarattınız!</li><li><strong>Ortak Veritabanı Kâbusu (Sonra Hepsi Uşağa):</strong> Geldik en acı tabloya. Onca servisi ayırdık, aralara kuyruklar (RabbitMQ, Kafka), API Gateway’ler koyduk. Peki veritabanları nerede? Herkes gidip “Uşak” adını verdiğimiz o hantal, tek parça veritabanına bağlanıyor! Aşçı tabloya yazarken lock koyuyor, Bahçıvan aynı tablodan veri çekerken timeout yiyor. Biz dağıtık mimari kurduğumuzu sanırken, aslında monolitik bir veritabanının önüne sadece “network gecikmesi” eklemiş olduk.</li></ul><h4>Malikânenin Görünmez Riskleri</h4><p>Ortak bir veritabanı üzerinde CQRS uygulamaya çalışmak, kod hamallığından başka bir şey değildir. Klasör yapınızı kalabalıklaştırmak sistemi dağıtık yapmaz. Bunun bedelini çok ağır ödersiniz:</p><ul><li><strong>Dağıtık Monolit Sendromu:</strong> Servisleri bağımsız canlıya (production) alamazsınız. Aşçıda yaptığınız ufak bir değişiklik Uşak servisi etkilediği için, bütün malikâneyi aynı anda test edip deploy etmeniz gerekir. Mikro servisin o çok övülen “çevikliği” daha ilk günden ölmüştür.</li><li><strong>İzlenebilirlik (Tracing) Cehennemi ve Kara Delikler:</strong> Bir hata olduğunda devasa log yığınlarında kaybolursunuz. Sorun Aşçıda mı başladı, Bahçıvanda mı takıldı, yoksa Uşak mı kilitledi bulana kadar saatler, bazen günler geçer. Bir de bunun tam zıttı olan <strong>“Kara Delik”</strong> versiyonu vardır: Sistemin hiçbir yerinde log tutulmaz. Hatalar try-catch bloklarında sessizce yutulur. Bir şeyler ters gittiğinde arka planda sistemin nasıl çalıştığı ve kimin kime ne gönderdiği tamamen “Allah bilir” durumundadır. Sistem can çekişir ama ortada ne bir kanıt vardır ne de bir ipucu; Uşak’ın cinayeti işlediğini hissedersiniz ama asla ispatlayamazsınız.</li></ul><p><strong>Küçülerek Hızlanmak: Modüler Monolite Dönüş Cesareti</strong></p><p>Madem Aşçı, Bahçıvan ve Şoför günün sonunda aynı Uşağa emir veriyor, o zaman aralarındaki o gereksiz ağ duvarlarını yıkmanın vakti geldi. Sektörde “monolite dönmek” başarısızlık gibi algılanır. Oysa iş kurallarını bozmadan, katı modül sınırları çizerek bu servisleri tek bir uygulamada (Modüler Monolit) birleştirmek, bugün alabileceğiniz en rasyonel ve olgun mimari karardır. (Tabii modül sınırlarını iyi çizmezseniz, sistemin hızla “<a href="https://www.minepla.net/2016/12/yazdigimiz-kodlar-nasil-big-ball-of-mud-oluyor/">Büyük Bir Çamur Topuna</a>” dönüşeceğini unutmayın).</p><p>Sistemi rasyonel boyutlara çekmenin getirileri devasadır:</p><ul><li><strong>Deployment Kâbusu Biter:</strong> 5 farklı servisi sırayla canlıya alma, patlarsa hepsini geri alma (rollback) stresi biter. Tek proje, tek deployment.</li><li><strong>Network Yükü Sıfırlanır:</strong> Servislerin birbirine HTTP isteği atıp token doğrulaması bitince, o çok maliyetli network çağrıları basit bir “metot (function) çağrısına” dönüşür.</li><li><strong>Bulut (Cloud) Faturaları İner:</strong> Gereksiz yere ayakta tutulan onlarca pod, cluster ve load balancer ortadan kalktığında, aylık binlerce dolarlık o faturanın aslında ödediğiniz bir “kötü mimari vergisi” olduğunu anlarsınız.</li></ul><p><strong>Ve AI İçin Temiz Bir Bağlam (Context)</strong></p><p><strong><em>1- AI Asistanları Kodu Nasıl “Görür”? (RAG ve Bağlam)</em></strong></p><p>AI araçları kodunuzun tamamını tek seferde hafızasına alamaz. Bunun yerine, IDE’nizdeki kodları indeksler ve siz bir soru sorduğunuzda (veya kod tamamlama istediğinizde) <strong>RAG (Retrieval-Augmented Generation)</strong> adı verilen bir yöntem kullanır. Yani sizin sorunuza yanıt verebilmek için, o anki dosyanızla anlamsal olarak en alakalı diğer kod parçacıklarını (snippet’leri) bulur ve bunları “context” (bağlam) olarak modele gönderir.</p><p><strong><em>2- Mikro Servislerin Yarattığı “Kör Noktalar”</em></strong></p><p>Mikro servis mimarilerinde projeler genellikle farklı repository’lere (depolara) bölünür veya en azından farklı solution/workspace’lerde yaşar.</p><ul><li><strong>Bağlantı Kopukluğu:</strong> Kodunuz POST https://payment-service/api/charge şeklinde bir HTTP çağrısı yaptığında, o çağrı AI için tam bir kara kutudur. Evet, elinizde projenin bir köşesinde duran bir Request/Response modeli veya eski bir Swagger dokümanı olabilir. Ancak mikro servis dünyasının acı bir gerçeği vardır: O anki güncel canlı ortamda, karşıdaki servisin <em>gerçekten</em> elinizdeki request&#39;i aynen kabul edip etmeyeceği veya tam olarak o response&#39;u dönüp dönmeyeceği meçhuldür. AI, o URL&#39;nin arkasında anlık olarak hangi versiyonun çalıştığına, hangi yeni kuralın eklendiğine kördür. Sonuç? Ya eski bir DTO&#39;ya bakıp halüsinasyon görür ya da sizden güncel kontrat kodlarını manuel olarak kopyalayıp prompt&#39;a yapıştırmanızı bekler.</li><li><strong>Halüsinasyonlar:</strong> Ödeme servisinin hangi DTO’yu (Data Transfer Object) beklediğini, hangi validasyon kurallarına sahip olduğunu göremez. AI bu durumda ya genel geçer tahminler yapar (halüsinasyon görür) ya da sizden o servisin Swagger dokümanını veya kodlarını manuel olarak prompt’a yapıştırmanızı bekler.</li><li><strong>Token İsrafı:</strong> Kodu manuel kopyalayıp AI’a yedirmek, hem sizin zamanınızı çalar hem de AI’ın “Token Window” (Bağlam Penceresi) limitlerini gereksiz yere doldurur. Token limiti doldukça AI’ın odaklanma yeteneği düşer ve saçmalamaya başlar.</li></ul><p><strong><em>3- Modüler Monolit ve “Nokta Atışı” Çözümler</em></strong></p><p>Sistemi modüler monolit olarak tasarladığınızda, tüm modüller (Aşçı, Bahçıvan, Şoför) aynı repository’de ve aynı IDE çalışma alanındadır (workspace).</p><ul><li><strong>İzlenebilir Bağımlılıklar:</strong> Ağ üzerinden atılan görünmez HTTP isteği, yerini IPaymentService.Charge(orderRequest) gibi somut bir arayüz (interface) çağrısına bırakır.</li><li><strong>Otomatik Keşif:</strong> AI, IPaymentService&#39;i gördüğü an IDE&#39;nin indeksleme gücünü kullanarak bunun implementasyonunu, DTO&#39;sunu ve veri tabanı entity&#39;sini anında bulur.</li><li><strong>Ekonomik Bağlam:</strong> AI, tüm projeyi değil, sadece o arayüzün ve ilgili metodun küçük kod bloklarını alıp bağlama ekler. Token limitiniz şişmez ve AI tüm resmi (büyük resmi değil, “ilgili” resmi) net bir şekilde gördüğü için size gerçekten de <strong>çalışan, bağlama uygun ve nokta atışı</strong> kodlar üretir.</li></ul><h4>İşin “Ama” Kısmı</h4><p>Burada dürüst olmak gerek: Eğer elinizdeki proje <strong>“Modüler”</strong> bir monolit değil de, her şeyin birbirine girdiği bir <strong>“Spagetti (Big Ball of Mud)”</strong> monolit ise, AI yine çuvallayacaktır. Çünkü binlerce satırlık “God Class”lar (Tanrı Sınıflar) ve her yerden her yere giden referanslar, AI gene zehirlenir. AI size alakalı alakasız tonla kodu bağlam olarak sunar ve yine token israfı yaşarsınız.</p><p><strong>Özetle:</strong> Temiz sınırlar (boundaries) çizilmiş, arayüzlerle (interfaces) ayrıştırılmış (fat interface olmamasına dikkat edilmeli) ama aynı kod tabanında yaşayan bir Modüler Monolit, günümüz yapay zeka asistanlarının <strong>en yüksek verimle</strong> çalıştığı mimaridir.</p><p>YTD (Yazılım tavsiyesi değildir!)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5454266ac4b1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devopsturkiye/ba%C5%9F%C3%A7%C4%B1van-mikro-servisler-spagetti-mimari-ve-ai-%C3%A7a%C4%9F%C4%B1nda-%C3%A7%C3%B6pe-at%C4%B1lan-tokenlar-5454266ac4b1">“Başçıvan Mikro Servisler” : Spagetti Mimari ve AI Çağında Çöpe Atılan Token’lar</a> was originally published in <a href="https://medium.com/devopsturkiye">Devops &amp; AI Türkiye☁️ 🐧 🐳 ☸️</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pipeline Pattern in .NET Core: Building Modular and Flexible Workflows]]></title>
            <link>https://logiwa.tech/pipeline-pattern-in-net-core-building-modular-and-flexible-workflows-7ec36f33ce90?source=rss-e3ddd311faec------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ec36f33ce90</guid>
            <category><![CDATA[design-patterns-in-csharp]]></category>
            <category><![CDATA[pipeline-pattern]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Hakan Karabulut]]></dc:creator>
            <pubDate>Wed, 06 Nov 2024 19:52:32 GMT</pubDate>
            <atom:updated>2024-11-16T01:35:19.596Z</atom:updated>
            <content:encoded><![CDATA[<h3>Pipeline Pattern in .NET Core: Building Modular and Flexible Workflows</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*twMZBYq-2IiT3xSSQSjQbA.png" /></figure><p>Yazımı Türkçe okumak için <a href="https://medium.com/devopsturkiye/net-coreda-pipeline-pattern-mod%C3%BCler-ve-esnek-i%CC%87%C5%9F-ak%C4%B1%C5%9Flar%C4%B1-olu%C5%9Fturma-7d6639ba90bf">Linke</a> tıklayabilirsiniz.</p><p>The pipeline pattern is a design pattern that enables performing operations on data in a chained manner by organizing them into specific steps or stages (pipeline). The primary goal of this pattern is to make the code more readable, modular, and extensible. When used for step-by-step processes, it provides a structure where each step represents an independent business logic, making it easily reusable.</p><p><strong>Working Principle:</strong></p><p>In the pipeline pattern, each step processes the data received from the previous step and passes its output to the next step, creating a data flow. Each stage (step) performs an independent operation, allowing each step in a sequence of operations to handle a different task, and making it easy to modify and reuse when needed.</p><p>Data flows from the initial input step through a series of handlers or stages. Each step processes and prepares the data to be passed to the next step. At the final step, the processed data is delivered to the user or an external system.</p><p>For example, consider a pipeline with data validation, transformation, and finally saving operations.</p><ul><li><strong>Step 1:</strong> Data validation is performed.</li><li><strong>Step 2:</strong> Data transformation is applied.</li><li><strong>Step 3:</strong> The transformed data is saved.</li></ul><p>These stages form a chain, and each step processes the data to make it suitable for the next step, functioning within a pipeline structure.</p><h3>Areas of Use</h3><p>The <strong>pipeline pattern</strong> is particularly useful in managing complex business processes and in scenarios where interconnected tasks need to be executed sequentially. This pattern organizes tasks as sequential steps, treating each one as an independent component. Each step processes the output of the previous step and passes it along to the next, making it highly advantageous in data processing and workflow scenarios. Some common situations where the pipeline pattern is preferred include:</p><ul><li><strong>Complex Business Processes</strong>: In intricate workflows, tasks may be logically interdependent. The pipeline pattern makes such complexity manageable by breaking the process into smaller, independent steps.</li><li><strong>Dependent Operations</strong>: When operations must follow a specific order and each operation depends on the output of the previous one, the pipeline pattern efficiently manages these dependencies.</li></ul><h3>Advantages</h3><ul><li><strong>Readability</strong>: With a step-by-step flow, the code structure becomes more understandable. The purpose and functionality of each step are clear.</li><li><strong>Testability</strong>: Each step can be tested independently, making debugging easier and ensuring each step functions correctly.</li><li><strong>Scalability</strong>: Adding a new step or modifying an existing one is straightforward. Adding a new operation to the pipeline simply involves defining a new step and inserting it into the sequence.</li></ul><p>For example, in a payment processing pipeline, you might have steps for validation, authorization, payment processing, and notification. This setup allows each step to operate independently, based on the output of the previous one, and makes it easy to update individual steps as needed.</p><h3>Implementing the Pipeline Pattern</h3><p>The <strong>pipeline pattern</strong> is especially useful when you want to process data through a series of steps. To implement this structure in C#, we can walk through a simple example step by step. First, we will define an IPipelineStep interface to represent each step, and a Pipeline class to manage the flow of data. Here are the steps for building this structure:</p><p><strong><em>1- Define the IPipelineStep Interface</em></strong></p><p>To ensure that each step has a common structure, we create the IPipelineStep interface. This interface will include a Process method, which will take the data to be processed and transform it.</p><p><a href="https://gist.github.com/karabuluthakan/487126cdd32dc8ca7b23804e33f41124">https://gist.github.com/karabuluthakan/487126cdd32dc8ca7b23804e33f41124</a></p><p>This interface allows data processing for any data type (using the generic type T) through the Process method.</p><p><strong><em>2. Define Different Steps</em></strong></p><p>Next, define different steps that inherit from the IPipelineStep interface. For example, let&#39;s consider a string processing scenario. We can define steps like ToUpperStep and AppendTextStep:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b271cc73bf4307ea580ed1f509c7e91b/href">https://medium.com/media/b271cc73bf4307ea580ed1f509c7e91b/href</a></iframe><p>In this example, the ToUpperStep converts the input to uppercase, while the AppendTextStep appends a given string to the end of the input.</p><p><strong><em>3. Define the Pipeline Class</em></strong></p><p>Now, let’s define the Pipeline class that will execute the steps in sequence. This class will hold the steps in a list and ensure they are executed in order.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d442255058f1db8605364485175d2111/href">https://medium.com/media/d442255058f1db8605364485175d2111/href</a></iframe><p>Here, the AddStep method allows us to add steps to the pipeline. The Execute method runs all the steps in sequence and returns the result.</p><p><strong><em>4. Using the Pipeline</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bf132fa59523784cae80e59a42aaba5/href">https://medium.com/media/4bf132fa59523784cae80e59a42aaba5/href</a></iframe><h4>Working Principle</h4><ul><li>Steps (such as ToUpperStep and AppendTextStep) are added to the Pipeline class in sequence.</li><li>When the Execute method is called, the data passes through these steps in order and is processed.</li></ul><p>With this structure, you can flexibly add or remove steps, and by defining multiple pipelines, you can create different processing sequences simultaneously.</p><h4>Benefits of the Pipeline Pattern</h4><ol><li><strong>Flexibility</strong>: Steps can be easily added, removed, or rearranged.</li><li><strong>Single Responsibility Principle</strong>: Each step performs only its specific task, which increases the clarity of the code.</li></ol><p>3.<strong> Reusability</strong>: Each step can be used independently in other projects.</p><h4>Connecting Steps in a Pipeline (Chain of Responsibility vs Pipeline)</h4><p>While the <strong>Pipeline Pattern</strong> and <strong>Chain of Responsibility</strong> are similar patterns, they have different use cases and behaviors. Both patterns are used to handle tasks sequentially, but they have some key differences.</p><p><strong><em>1. Processing Order and Structure</em></strong></p><ul><li><strong><em>Pipeline Pattern:</em></strong> The order of operations is defined upfront, and each step follows the next. There are no branches or alternative paths in the workflow; the tasks are processed in a fixed, sequential order. For example, using a pipeline is ideal in scenarios where each step, such as a data validation process, must be completed in a specific sequence.</li><li><strong><em>Chain of Responsibility: </em></strong>Operations are handled sequentially within a chain, but each step can decide which operation to proceed with or whether to continue to the next. This pattern allows for branching and evaluating different paths, as each handler has the flexibility to either process the incoming request or pass it along to the next handler. Therefore, <strong>Chain of Responsibility</strong> is more suitable in cases where the process needs to take different paths depending on certain conditions.</li></ul><p><strong><em>2. Process Control and Termination</em></strong></p><ul><li><strong>Pipeline Pattern</strong>: Each step is structured to pass the data to the next step, with each step taking over the data from the previous one. If an error occurs in a step due to a certain condition, the entire flow is typically halted. The <strong>Pipeline Pattern</strong> is more suitable for continuous processes that follow a specific logical sequence.</li><li><strong>Chain of Responsibility</strong>: When a process needs to be terminated, it can be done flexibly. For instance, when a certain condition is met, the chain can end, or a specific handler can process the request and bypass the remaining chain. This is particularly useful in scenarios that require flexible termination or branching.</li></ul><p><strong><em>3. Typical Use Cases</em></strong></p><p><strong><em>3.1 Pipeline Pattern:</em></strong> The pipeline is ideal for scenarios where data is passed through a series of processes, with each step passing the result to the next. Examples include:</p><ul><li>Data processing and transformation tasks (such as ETL processes).</li><li>Validation tasks, logging, or processes that need to be executed in a fixed sequence.</li><li>Particularly used for creating middleware structures in <strong>.NET Core</strong>.</li></ul><p><strong><em>3.2 Chain of Responsibility: </em></strong>The Chain of Responsibility pattern is preferred in scenarios where a handler can be triggered based on different conditions or can terminate the process. Examples include:</p><ul><li>Situations where a support line needs to route requests based on certain conditions.</li><li>Authorization and access control processes that are executed based on different conditions.</li><li>Scenarios where different processing chains need to be dynamically activated or deactivated.</li></ul><h3>When is the Pipeline Pattern More Suitable?</h3><p>The <strong>Pipeline Pattern</strong> is particularly suitable when there is a fixed sequence and continuity between operations. It is used in processes where each step performs a task in the predefined order without interacting with other steps, where the operations work independently, and the flow is stable. The pipeline pattern is especially effective in systems that require data validation, transformation, or a fixed sequence of logic.</p><p>In summary, there are significant differences between the <strong>Pipeline Pattern</strong> and <strong>Chain of Responsibility</strong> in terms of processing order, branching, and task structure. While the <strong>Pipeline</strong> is more suitable for scenarios that require a sequential, fixed workflow, the <strong>Chain of Responsibility</strong> is ideal for situations where flexible handler chains are needed.</p><h4>Exception Handling and Error Management in a Pipeline</h4><p>Error management in pipeline steps should be handled carefully, considering that each step potentially performs an independent operation. To determine how erroneous steps impact the workflow, actions based on the type of error can be addressed with different strategies. Below are some methods for handling errors that occur in pipeline steps and how these errors can affect the workflow:</p><p><strong><em>1. Redirecting Faulty Steps to a Specific Condition (Fallback Strategy)</em></strong></p><p>If an error occurs in a step along the pipeline, the workflow can be directed to continue under a specific condition. For example, a failed step could either terminate the workflow or be redirected to an alternative path. In this case, fallback strategies are applied.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/992baf5a029253c9aa61d930e2ce7963/href">https://medium.com/media/992baf5a029253c9aa61d930e2ce7963/href</a></iframe><p><strong>Impact:</strong></p><ul><li>Faulty steps do not directly stop the workflow.</li><li>The impact of the error can be mitigated with alternative processes.</li></ul><p><strong><em>2. Error Catching and Logging</em></strong></p><p>Adding error catching and logging mechanisms in each pipeline step makes it easier to identify issues, and error management is handled through a central logging system for all steps.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afb47e7a6f3806e605352c309aa4c378/href">https://medium.com/media/afb47e7a6f3806e605352c309aa4c378/href</a></iframe><p><strong>Impact:</strong></p><ul><li>Error information is stored, allowing the cause of the error to be analyzed.</li><li>Logs record errors centrally, and the workflow can be stopped or continued as needed based on the information.</li></ul><p><strong><em>3. Workflow Termination (Fail-Fast Strategy)</em></strong></p><p>If certain steps in the pipeline are critical, an error in these steps can halt the entire pipeline. This method is called the fail-fast strategy, where the workflow is stopped before the faulty process reaches the next steps.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/438b43f9a1947f1aac55ddc0a61f82b2/href">https://medium.com/media/438b43f9a1947f1aac55ddc0a61f82b2/href</a></iframe><p><strong>Impact:</strong></p><ul><li>Prevents the workflow from continuing unnecessarily in case of critical errors.</li><li>Facilitates error analysis and resource management.</li></ul><p><strong><em>4. Continuing with Error Suppression</em></strong></p><p>In some pipeline steps, even if an error occurs, the workflow may need to continue. In this case, when an error happens, the workflow does not break; instead, the error is suppressed, and the pipeline moves on to the next step. This is used in fault-tolerant applications.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/065e4093d3f3ec1352c1aa7f16c82e56/href">https://medium.com/media/065e4093d3f3ec1352c1aa7f16c82e56/href</a></iframe><p><strong>Impact:</strong></p><ul><li>Prevents errors from completely stopping the workflow.</li><li>It is only preferred for non-critical errors; however, since the error is ignored, it can lead to data inconsistency.</li></ul><p><strong><em>5. Attempting to Resolve the Error with the Retry Pattern</em></strong></p><p>Some errors may be temporary (e.g., network connection errors), so the retry pattern can be applied to attempt to resolve the error. If the retry steps fail after a certain number of attempts, the workflow can be redirected to a different strategy.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9009ae982fe6fed43af73a6773bcca06/href">https://medium.com/media/9009ae982fe6fed43af73a6773bcca06/href</a></iframe><p><strong>Impact:</strong></p><ul><li>Allows the workflow to continue in case of temporary errors.</li><li>Increases the likelihood of success, but may extend the response time.</li></ul><p><strong><em>6. Using a Result Object for Status Reporting</em></strong></p><p>When handling errors, each step can return a result object. This object contains information about whether the operation was successful or failed, the type of error (if any), and an error message if necessary. This allows you to observe which errors occurred at which step by the end of the pipeline.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f512d9524a16628031747eb760bbe699/href">https://medium.com/media/f512d9524a16628031747eb760bbe699/href</a></iframe><p><strong>Impact:</strong></p><ul><li>Allows errors to be tracked without stopping the workflow.</li><li>Enables reporting and analysis of errors at specific steps.</li></ul><p>The error management strategy applied in pipeline steps depends on the structure of the workflow and the criticality of each step. While fail-fast can be applied to critical operations, retry or error suppression strategies can be used for fault-tolerant operations. This way, errors are managed without compromising the integrity of the workflow, enhancing the system’s resilience.</p><h4>Performance and Testability</h4><p>The Pipeline pattern is a design pattern that ensures a sequence of processing steps is carried out in order. This pattern is particularly useful when the processing steps follow each other, and data is processed at each step. The impact of the Pipeline pattern on performance and its contributions to testability can be discussed as follows:</p><ol><li><strong><em>Impact on Performance</em></strong></li></ol><ul><li><strong>Parallel Processing:</strong> If the steps in the pipeline are independent of each other, they can be executed in parallel. This can significantly reduce processing times since the steps can run concurrently instead of waiting for each other.</li><li><strong>Early Exit:</strong> Each step in the pipeline can terminate the process when a certain condition is met. This avoids unnecessary processing steps, ensuring that only the necessary steps are executed, which leads to improved performance.</li><li><strong>Optimization and Resource Utilization:</strong> Due to the sequential nature of the pipeline pattern, resources (memory, processing power, etc.) can be utilized more efficiently. The steps can influence each other in a specific order, preventing unnecessary resource consumption.</li></ul><p><strong><em>2. Contributions to Testability</em></strong></p><p>The Pipeline pattern enables each step to be tested independently. This is a key feature that enhances the testability of the software. The flexibility and reliability provided by step-by-step testing are as follows:</p><ul><li><strong>Independent Tests:</strong> Each pipeline step can be tested individually. This makes it easier to isolate errors that may occur at each step. If an error occurs, it is likely to be in a specific step, making debugging faster and more efficient.</li><li><strong>Isolation of Performed Operations:</strong> Testing each step independently ensures there are no external effects between the steps. For example, if a database query is executed at each step, independent testing guarantees that each step works correctly.</li><li><strong>Testability and Robustness:</strong> The ability to test steps independently contributes to the robustness of the pipeline. Understanding which step caused an error becomes easier by testing only a specific part, which increases the reliability of the software.</li><li><strong>Refactoring and Change Management:</strong> Changes made in the pipeline are only tested on the affected step, enhancing the sustainability of the software. Additionally, when a step needs refactoring, it is sufficient to test only the relevant step, not the entire pipeline.</li></ul><p><strong><em>3. Sample Scenario:</em></strong></p><p>This scenario of testing each step of an order processing pipeline in an e-commerce application is a great way to ensure the reliability and accuracy of the process. Since you have experience with software development and backend systems, you’d likely appreciate the clear separation of concerns that each independent test provides. This makes debugging and maintenance much easier, especially when you consider how each step — payment processing, stock control, and order status updates — can be validated in isolation.</p><p>Given your background with microservices and integrating systems, this approach aligns well with modular development principles. Testing individual components independently not only improves test coverage but also ensures that each part of the system works as expected before they are combined, reducing the likelihood of complex bugs in production.</p><p>In terms of performance, optimizing the pipeline to allow for parallel processing would further speed up these operations, especially if each step (like payment or stock check) can run independently. This approach, alongside the ability to quickly test each step in isolation, should provide both efficiency and reliability, which are key when managing larger systems like the ones you’re working with.</p><p>Overall, the Pipeline pattern’s ability to modularize and streamline processes makes it a solid fit for any application with complex workflows, whether it’s for an e-commerce platform or a warehouse management system.</p><h4>Parallelism in the Pipeline Pattern</h4><p>Parallelism allows multiple steps to be executed simultaneously, reducing processing times and increasing efficiency. However, applying parallelism requires specific conditions to be met. Let’s explore when parallel processing is advantageous and the conditions for its successful application in the pipeline pattern.</p><h4>When is Parallelism Beneficial?</h4><p>Parallelism can be advantageous in the following situations:</p><ul><li><strong>Independent Steps:</strong> If the steps in the pipeline are independent of each other (i.e., the output of one step is not related to the input of another), these steps can be executed in parallel. In this case, parallel processing can significantly reduce the overall processing time.</li><li><strong>CPU-bound Operations:</strong> If the steps involve computationally intensive tasks (CPU-bound), parallel processing allows each step to be executed in a separate thread, making more efficient use of processing power.</li><li><strong>I/O-bound Operations:</strong> If the steps involve I/O operations (such as data reading/writing, network calls), parallel processing allows these I/O tasks to be executed concurrently. This can save time, as I/O operations often involve waiting periods.</li><li><strong>Big Data Processing:</strong> If the pipeline processes large datasets, parallel processing speeds up the tasks. The datasets can be divided, and each portion can be processed in parallel.</li></ul><p><strong>Parallel Steps with Task and Parallel in C#</strong></p><p>There are different tools available in C# to manage parallel steps. The most commonly used ones are the Task and Parallel classes. Both classes are used to manage parallel processing, but their usage scenarios are different.</p><ol><li><strong><em>Parallel Processing with Task</em></strong></li></ol><p>Task is a structure suitable for asynchronous operations. To implement parallel execution using Task, we can do the following:</p><ul><li>For each step, we create a Task and use Task.WhenAll to wait for the completion of all tasks.</li></ul><p><em>Example :</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14b530bf04700bbc35eb63b5120182f1/href">https://medium.com/media/14b530bf04700bbc35eb63b5120182f1/href</a></iframe><p>In this example, three tasks are started in parallel, and the program waits until all steps are completed. This way, you can reduce the total time required for each step to finish.</p><p><strong><em>2. Parallel Processing with Parallel</em></strong></p><p>The Parallel class manages parallel execution when performing operations on data of the same type. It is particularly useful for processing large datasets, and methods like Parallel.ForEach are commonly used.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed09a1d97dcd18284a33d13226af89a4/href">https://medium.com/media/ed09a1d97dcd18284a33d13226af89a4/href</a></iframe><p>In this example, Parallel.ForEach processes each item in parallel. This can improve performance when handling large datasets by processing the data collection in parallel.</p><p><strong><em>Managing Parallel Steps</em></strong></p><p>When performing parallel processing, there are several key considerations to keep in mind:</p><ol><li><strong>Data Sharing: </strong>Data sharing between parallel operations must be managed carefully. When accessing shared resources, locking mechanisms can be used to prevent data inconsistencies.</li><li><strong>Post-Processing Conditions:</strong> Even if parallel steps in the pipeline are independent of each other, sometimes the steps need to be executed sequentially. For example, if one step provides data to another, it should be processed in order.</li><li><strong>Error Handling:</strong> Managing errors that occur in each step of parallel tasks is crucial. When using Task.WhenAll, error handling must be addressed. For instance, instead of stopping the entire pipeline when one task fails, you can isolate the faulty step and continue processing the others.</li><li><strong>Resource Usage:</strong> Parallel processing always requires additional processing power and resource usage. Therefore, it is important to monitor how parallel tasks impact system resources and ensure that the number of parallel tasks is appropriate to avoid unnecessary resource consumption.</li></ol><p>Achieving parallelism in the pipeline pattern can accelerate processes and increase efficiency. However, the advantages of parallel processing are limited to situations where the steps are independent and the type of processing is suitable. Managing parallel steps in C# using tools like Task and Parallel enables performance improvements. Proper use of these tools ensures faster and more efficient pipeline processes.</p><h3>Conclusion</h3><p>The Pipeline pattern not only facilitates the creation of modular and flexible workflows, but it can also enhance application performance and improve testability. Especially in processes involving data processing, validation, and transformation, ensuring that each step operates independently and is combined in sequence makes complex workflows more manageable.</p><p>This pattern offers applicability, scalability, and flexibility, while independent testing of each step aids in the early detection of errors in the software development process. Additionally, the ability to perform parallel processing allows for acceleration in large-scale data processing as well as CPU or I/O-bound tasks.</p><p>In conclusion, the Pipeline pattern emerges as a method that strengthens the resilience of software while improving the sustainability of systems. It not only ensures that the code is more understandable, flexible, and testable, but also provides significant advantages in areas such as error management and performance optimization at each step.</p><p><em>Mit freundlichen Grüßen</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ec36f33ce90" width="1" height="1" alt=""><hr><p><a href="https://logiwa.tech/pipeline-pattern-in-net-core-building-modular-and-flexible-workflows-7ec36f33ce90">Pipeline Pattern in .NET Core: Building Modular and Flexible Workflows</a> was originally published in <a href="https://logiwa.tech/">Logiwa Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[.NET Core’da Pipeline Pattern: Modüler ve Esnek İş Akışları Oluşturma]]></title>
            <link>https://medium.com/devopsturkiye/net-coreda-pipeline-pattern-mod%C3%BCler-ve-esnek-i%CC%87%C5%9F-ak%C4%B1%C5%9Flar%C4%B1-olu%C5%9Fturma-7d6639ba90bf?source=rss-e3ddd311faec------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d6639ba90bf</guid>
            <category><![CDATA[pipeline-pattern]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[pipeline]]></category>
            <category><![CDATA[net-core]]></category>
            <dc:creator><![CDATA[Hakan Karabulut]]></dc:creator>
            <pubDate>Wed, 06 Nov 2024 09:56:15 GMT</pubDate>
            <atom:updated>2024-11-16T01:36:28.393Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*twMZBYq-2IiT3xSSQSjQbA.png" /></figure><p>You can click the <a href="https://karabuluthakan.medium.com/pipeline-pattern-in-net-core-building-modular-and-flexible-workflows-7ec36f33ce90">Link</a> to read my article in English.</p><p>Pipeline pattern, işlemleri belirli adımlar veya aşamalar halinde sıralayarak (pipeline) veri üzerinde zincirleme bir şekilde işlem yapmayı sağlayan bir tasarım desenidir. Bu desenin temel amacı, kodu daha okunabilir, modüler ve genişletilebilir yapmaktır. Özellikle adım adım ilerleyen işlemler için kullanıldığında, her adımın bağımsız bir iş mantığını temsil ettiği ve kolayca yeniden kullanılabilir hale getirildiği bir yapı sunar.</p><p><strong>Çalışma Prensibi:</strong></p><ol><li>Pipeline pattern’de, her adım bir önceki adımdan gelen veriyi işler ve çıktısını bir sonraki adıma aktarır. Bu, bir veri akışı (data flow) oluşturur.</li><li>Her aşama (step), bağımsız bir işlem gerçekleştirir. Bu sayede, belirli bir işlem zincirindeki her adım, farklı bir görevi üstlenebilir ve gerektiğinde kolayca değiştirilip yeniden kullanılabilir.</li><li>Veri, başlangıçtaki giriş adımından başlayarak bir dizi işleyici (handler) veya aşama boyunca ilerler. Her adım, veriyi bir sonraki adıma aktarılacak şekilde işleyip hazırlar.</li><li>Son adımda ise verinin son hali kullanıcıya veya dış bir sisteme iletilir.</li></ol><p>Örneğin, bir veri doğrulama, dönüştürme ve son olarak kaydetme işlemleri olan bir pipeline düşünelim:</p><ul><li><strong>1. Adım:</strong> Veri doğrulama (validasyon) işlemi yapılır.</li><li><strong>2. Adım:</strong> Veri dönüşümü yapılır.</li><li><strong>3. Adım:</strong> Dönüştürülmüş veri kaydedilir.</li></ul><p>Bu aşamalar bir zincir oluşturur ve her adım, veriyi bir sonraki adıma uygun hale getirerek bir boru hattı (pipeline) yapısı içinde işler.</p><h4>Kullanım Alanları</h4><p>Pipeline pattern, özellikle <strong>karmaşık iş süreçlerinin</strong> yönetilmesinde ve <strong>birbirine bağımlı işlemlerin</strong> sırasıyla gerçekleştirilmesi gereken durumlarda tercih edilir. Bu desen, işlemleri ardışık adımlar halinde düzenleyerek her adımı ayrı bir bileşen olarak ele almayı sağlar. Her adım, kendinden önceki adımın sonucunu alıp işleyerek bir sonraki adıma aktarır. Bu yapı, veri işleme ve iş akışı senaryolarında büyük avantaj sağlar. Pipeline pattern’in tercih edildiği bazı durumlar:</p><p><strong>Karmaşık İş Süreçleri</strong>: Karmaşık iş akışlarında, işlemler mantıksal olarak birbirine bağımlı olabilir. Bu desen, süreci küçük ve bağımsız adımlara bölerek karmaşıklığı yönetilebilir hale getirir.</p><p><strong>Bağımlı İşlemler</strong>: İşlemler belirli bir sıraya bağlı olarak yapılmalıdır ve bir işlem, önceki işlemin çıktısını kullanıyorsa, pipeline pattern bu tür bağımlılıkları daha etkin şekilde yönetir.</p><h4>Avantajları</h4><p><strong>Okunabilirlik</strong>: İşlemler adım adım ilerlediği için, kodun yapısı daha anlaşılır hale gelir. Her adımın amacı ve işlevi açıkça görülebilir.</p><p><strong>Test Edilebilirlik</strong>: Her adım tek başına test edilebilir. Bu, hata ayıklamayı kolaylaştırır ve her bir adımın doğru çalıştığından emin olunmasını sağlar.</p><p><strong>Genişletilebilirlik</strong>: Yeni bir adım eklemek veya mevcut adımlardan birini değiştirmek oldukça kolaydır. Pipeline’a yeni bir işlem eklemek, yalnızca yeni bir adım tanımlayıp sıraya eklemek anlamına gelir.</p><p>Örneğin, bir ödeme işleme sürecinde öncelikle doğrulama, ardından yetkilendirme, ödeme işlemi ve son olarak bildirim adımlarını içeren bir pipeline kurulabilir. Bu sayede her adım, bir önceki adımın çıktısına dayalı olarak bağımsız bir modül gibi çalışır ve gerektiğinde kolayca güncellenebilir.</p><h4>Pipeline Pattern’in Uygulanması</h4><p>Pipeline pattern, özellikle bir veri işlemini bir dizi adım üzerinden geçirerek işlemek istediğinizde oldukça kullanışlıdır. Bu yapıyı C# ile uygulamak için basit bir örnek üzerinden adım adım gösterebiliriz. Öncelikle, her adımı temsil eden bir IPipelineStep arayüzü ve bir Pipeline sınıfı tanımlayacağız. İşte bu yapıyı oluşturmanın aşamaları:</p><ol><li><strong>IPipelineStep Arayüzünü Tanımlayın</strong></li></ol><p>Her adımın ortak bir yapısı olması için IPipelineStep arayüzünü oluşturuyoruz. Bu arayüz, işlem yapılacak veriyi alıp dönüştüren bir Process metodunu içerecek.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c29a80014782da4a47a2f771b1c9ff5/href">https://medium.com/media/6c29a80014782da4a47a2f771b1c9ff5/href</a></iframe><p>Bu arayüz, Process metodu aracılığıyla herhangi bir veri tipinde (generic olarak T tipi ile) veri işlemi yapılmasını sağlar.</p><p>2. <strong>Farklı Adımları Tanımlayın</strong></p><p>Ardından, IPipelineStep arayüzünden türeyen farklı adımları oluşturun. Örneğin, bir string işleme sürecini ele alalım. ToUpperStep ve AppendTextStep gibi adımlar tanımlayalım:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b271cc73bf4307ea580ed1f509c7e91b/href">https://medium.com/media/b271cc73bf4307ea580ed1f509c7e91b/href</a></iframe><p>Bu örnekte, ToUpperStep girdiyi büyük harfe dönüştürürken, AppendTextStep verilen bir metni girdinin sonuna ekler.</p><p>3. <strong>Pipeline Sınıfını Tanımlayın</strong></p><p>Şimdi adımları sırayla çalıştıracak Pipeline sınıfını tanımlayalım. Bu sınıf, bir liste şeklinde adımları tutacak ve bu adımların sırasıyla çalıştırılmasını sağlayacak.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d442255058f1db8605364485175d2111/href">https://medium.com/media/d442255058f1db8605364485175d2111/href</a></iframe><p>Burada AddStep metodu ile pipeline’a adım ekleyebiliriz. Execute metodu ise sırayla tüm adımları çalıştırarak sonuç döndürür.</p><p>4. <strong>Pipeline’ı Kullanma</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bf132fa59523784cae80e59a42aaba5/href">https://medium.com/media/4bf132fa59523784cae80e59a42aaba5/href</a></iframe><h4>Çalışma Prensibi</h4><ul><li>Pipeline sınıfına adımlar (ToUpperStep ve AppendTextStep) sırasıyla eklenir.</li><li>Execute metodu çağrıldığında, veri bu adımlardan sırasıyla geçerek işlenir.</li></ul><p>Bu yapı sayesinde istediğiniz adımları esnek bir şekilde ekleyip çıkarabilir, aynı anda birden fazla pipeline tanımlayarak farklı işlem dizileri oluşturabilirsiniz.</p><h4>Pipeline Pattern’in Faydaları</h4><ol><li><strong>Esneklik</strong>: Adımlar kolayca eklenebilir, çıkarılabilir veya yeniden düzenlenebilir.</li><li><strong>Tek Sorumluluk İlkesi</strong>: Her adım yalnızca kendi görevini yerine getirir, bu da kodun anlaşılabilirliğini artırır.</li><li><strong>Yeniden Kullanılabilirlik</strong>: Her adım diğer projelerde de bağımsız olarak kullanılabilir.</li></ol><h4>Pipeline’da Adımların Birbirine Bağlanması (Chain of Responsibility vs Pipeline)</h4><p>Pipeline Pattern ve Chain of Responsibility birbirine benzer desenler olsa da, farklı kullanım alanları ve davranışları vardır. Her iki desen de işlemleri ardışık olarak ele almak için kullanılır, ancak bazı temel farkları bulunur.</p><p><em>1- İşleme Sırası ve Yapısı</em></p><ul><li><strong>Pipeline Pattern:</strong> İşlem sırası baştan belirlenir ve her adım bir sonrakini takip eder. İş akışında bir dallanma veya alternatif yol yoktur; işlemler aynı sırada ve sıralı olarak işlenir. Örneğin, bir veri doğrulama süreci gibi her adımın belirli bir sırada tamamlanması gerektiği durumlarda pipeline kullanmak idealdir.</li><li><strong>Chain of Responsibility:</strong> İşlemler bir zincir içinde sırayla ele alınır, ancak her adım kendinden sonra hangi işleme geçileceğine veya devam edip etmeyeceğine karar verebilir. Bu desen, dallanma ve farklı yolları değerlendirme yeteneğine sahiptir, çünkü her bir işleyici, gelen isteği işlemek veya bir sonraki işleyiciye geçmek gibi esnek bir yapıya sahiptir. Bu nedenle Chain of Responsibility, özellikle işlemin farklı koşullara göre farklı yollar izlemesi gerektiğinde daha uygundur.</li></ul><p><em>2- İşlem Kontrolü ve Durma</em></p><ul><li><strong>Pipeline Pattern:</strong> Her adım, bir sonraki adıma veriyi devretmek üzere yapılandırılmıştır ve her adım, veriyi bir üst işlemden devralır. İşlem sırasında bir adım, belirli bir koşuldan ötürü hatayla karşılaşsa bile, genellikle tüm akışın kesilmesi gerekir. Pipeline Pattern, sürekli işleyen ve belirli bir mantık sırasına göre akan işlemler için daha uygundur.</li><li><strong>Chain of Responsibility:</strong> Bir işlem durdurulması gerektiğinde bunu esnek bir şekilde sağlayabilir. Örneğin, belirli bir koşula ulaşıldığında zincirin sona ermesi veya belirli bir işleyici tarafından işlem yapılması ve kalan zincirin bypass edilmesi mümkündür. Bu, özellikle esnek bir durma veya dallanma gerektiren senaryolarda kullanışlıdır.</li></ul><p><em>3- Tipik Kullanım Senaryoları</em></p><p><strong>3.1 Pipeline Pattern:</strong> Pipeline, verinin bir dizi işlemden geçirilip, her işlemden sonra bir sonraki işleme devredildiği senaryolar için idealdir. Örneğin:</p><ul><li>Veri işleme ve dönüşüm işlemleri (ETL süreçleri gibi).</li><li>Doğrulama işlemleri, loglama veya sabit bir sırada yapılması gereken işlemler.</li><li>Özellikle .NET Core’da middleware (ara katman) yapısının oluşturulmasında kullanılır.</li></ul><p><strong>3.2 Chain of Responsibility:</strong> Chain of Responsibility ise bir işleyicinin farklı koşullara göre devreye gireceği veya işlemi sonlandırabileceği senaryolarda tercih edilir. Örneğin:</p><ul><li>Destek hattında belirli bir koşula göre yönlendirme yapılması gereken durumlar.</li><li>Yetkilendirme ve erişim kontrollerinin farklı koşullara göre çalıştırılması.</li><li>Farklı işleme zincirlerinin dinamik olarak devreye alınması veya devreden çıkarılması gereken durumlar.</li></ul><h4>Ne Zaman Pipeline Daha Uygundur?</h4><p>Pipeline Pattern, özellikle işlemler arasında sabit bir sıra ve devamlılık olması gereken durumlarda daha uygundur. Her adımın diğer adımlarla etkileşime girmeden, belirlenen sırada bir görevi yerine getirdiği, işlemlerin bağımsız şekilde çalıştığı ve akışın sabit olduğu süreçlerde pipeline kullanımı tercih edilir. Özellikle veri doğrulama, dönüşüm veya sabit mantık sıralaması gerektiren sistemlerde Pipeline Pattern hem basit hem de etkilidir.</p><p>Kısaca, Pipeline Pattern ve Chain of Responsibility arasında işlem sırası, dallanma ve işlem yapısı açısından önemli farklar bulunur. Pipeline, ardışık, sabit bir iş akışı gerektiren durumlarda daha uygunken, Chain of Responsibility esnek işleyici zincirlerine ihtiyaç duyulan durumlar için idealdir.</p><h4>Exception Handling ve Pipeline’da Hata Yönetimi</h4><p>Pipeline adımlarında hata yönetimi, her adımın potansiyel olarak bağımsız bir işleme sahip olduğu göz önüne alındığında özenle ele alınmalıdır. Hatalı adımların iş akışını nasıl etkileyeceğini belirlemek için, hata türüne göre yapılacak işlemler farklı stratejilerle ele alınabilir. Aşağıda, pipeline adımlarında meydana gelen hataların ele alınması ve bu hataların iş akışını nasıl etkileyebileceği üzerine bazı yöntemler paylaşılmıştır:</p><h4><strong><em>1. Hatalı Adımların Belirli Bir Duruma Yönlendirilmesi (Fallback Strategy)</em></strong></h4><p>Pipeline boyunca bir adımda hata oluşursa, iş akışının belirli bir durumda devam etmesi sağlanabilir. Örneğin, başarısız olan bir adım iş akışını tamamlamadan sonlandırabilir veya alternatif bir yola yönlendirilebilir. Bu durumda, fallback stratejileri uygulanır.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/992baf5a029253c9aa61d930e2ce7963/href">https://medium.com/media/992baf5a029253c9aa61d930e2ce7963/href</a></iframe><p><strong>Etkisi</strong>:</p><ul><li>Hatalı adımlar iş akışını doğrudan durdurmaz.</li><li>Alternatif işlemlerle hatanın etkisi azaltılabilir.</li></ul><h4>2. Hata Yakalama ve Loglama</h4><p>Her bir pipeline adımında hata yakalama ve loglama mekanizması eklemek, sorunların belirlenmesini kolaylaştırır ve adımların hata yönetimi merkezi bir loglama sistemi üzerinden sağlanır.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afb47e7a6f3806e605352c309aa4c378/href">https://medium.com/media/afb47e7a6f3806e605352c309aa4c378/href</a></iframe><p><strong>Etkisi</strong>:</p><ul><li>Hata bilgisi saklanarak, hatanın nedeni analiz edilebilir.</li><li>Loglar ile hataların merkezi bir yerde kaydı tutulur ve iş akışını gerektiğinde durdurur veya devam ettirir.</li></ul><h4>3. İ<strong>ş Akışının Kesilmesi (Fail-Fast Strategy)</strong></h4><p>Eğer pipeline’da belirli adımlar kritik öneme sahipse, bu adımlarda meydana gelen bir hata tüm pipeline’ı durdurabilir. Bu yönteme fail-fast denir ve böylece hatalı işlem bir sonraki adımlara ulaşmadan iş akışı durdurulur.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/438b43f9a1947f1aac55ddc0a61f82b2/href">https://medium.com/media/438b43f9a1947f1aac55ddc0a61f82b2/href</a></iframe><p><strong>Etkisi:</strong></p><ul><li>Kritik hatalarda iş akışının gereksiz yere devam etmesini engeller.</li><li>Hata analizini ve kaynak yönetimini kolaylaştırır.</li></ul><h4>4. Hataların Yumuşatılarak Devam Ettirilmesi (Error Suppression)</h4><p>Bazı pipeline adımlarında hata oluşsa bile, iş akışının devam etmesi istenebilir. Bu durumda, hata meydana geldiğinde iş akışı bozulmaz, hata bastırılır ve bir sonraki adıma geçilir. Bu, toleranslı uygulamalarda kullanılır.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/065e4093d3f3ec1352c1aa7f16c82e56/href">https://medium.com/media/065e4093d3f3ec1352c1aa7f16c82e56/href</a></iframe><p><strong>Etkisi:</strong></p><ul><li>Hataların iş akışını tamamen durdurmasını engeller.</li><li>Yalnızca kritik olmayan hatalarda tercih edilir; ancak hata göz ardı edildiği için veri tutarsızlığına yol açabilir.</li></ul><h4>5. Retry Pattern ile Hatanın Giderilmeye Çalışılması</h4><p>Bazı hatalar geçici olabilir (örneğin, ağ bağlantısı hataları), bu nedenle tekrar deneme (retry) pattern’i uygulanarak hatanın giderilmeye çalışılması sağlanabilir. Retry adımları belirli sayıda tekrardan sonra başarısız olursa iş akışının farklı bir stratejiye yönlendirilmesi sağlanır.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9009ae982fe6fed43af73a6773bcca06/href">https://medium.com/media/9009ae982fe6fed43af73a6773bcca06/href</a></iframe><p><strong>Etkisi</strong>:</p><ul><li>Geçici hatalarda iş akışının devam etmesi sağlanır.</li><li>Başarılı olma olasılığını artırır, fakat yanıt süresini uzatabilir.</li></ul><h4>6. <strong>Result Objesi Kullanımı ile Durum Raporlama</strong></h4><p>Hata yönetimi yaparken her adım bir sonuç objesi dönebilir. Bu obje, işlemin başarılı veya hatalı olduğunu, hatanın türünü ve gerekirse hata mesajını içerir. Böylece pipeline sonunda hangi adımda hangi hataların oluştuğu gözlemlenebilir.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f512d9524a16628031747eb760bbe699/href">https://medium.com/media/f512d9524a16628031747eb760bbe699/href</a></iframe><p><strong>Etkisi</strong>:</p><ul><li>Hataların iş akışını durdurmadan izlenmesini sağlar.</li><li>Hataların hangi adımlarda oluştuğunu raporlayarak analiz edilmesine olanak tanır.</li></ul><p>Pipeline adımlarında hata yönetimi için uygulanacak strateji, iş akışının yapısına ve her adımın kritik seviyesine bağlıdır. Kritik işlemlerde fail-fast uygulanabilirken, toleranslı işlemler için retry veya error suppression stratejisi uygulanabilir. Bu sayede, hatalar iş akışının bütünlüğünü bozmadan yönetilir ve sistemin dayanıklılığı artırılır.</p><h4>Performans ve Test Edilebilirlik</h4><p>Pipeline pattern, bir dizi işlem adımının ardışık olarak gerçekleştirilmesini sağlayan bir tasarım desenidir. Bu desen, özellikle işlem adımlarının birbirini takip ettiği ve her adımda veri üzerinde işlem yapıldığı durumlarda faydalıdır. Pipeline pattern’in performans üzerindeki etkilerini ve adım adım işleyişin test edilebilirliğe katkılarını şu şekilde ele alabiliriz:</p><ol><li><strong><em>Performans Üzerindeki Etkiler</em></strong></li></ol><ul><li><strong>Paralel İşlem Yapabilme</strong>: Eğer pipeline’daki adımlar birbirinden bağımsızsa, bu adımlar paralel olarak çalıştırılabilir. Bu, işlem sürelerini önemli ölçüde kısaltabilir, çünkü adımlar birbirini beklemek yerine aynı anda çalışabilir.</li><li><strong>Erken Çıkış (Early Exit)</strong>: Pipeline’daki her adım, belirli bir şart sağlandığında işlemi sonlandırabilir. Bu, gereksiz işlem adımlarından kaçınılmasını sağlar, yani sadece gerekli adımlar çalıştırılarak performans artışı sağlanabilir.</li><li><strong>Optimizasyon ve Kaynak Kullanımı</strong>: Pipeline pattern, belirli adımların birbirini takip etmesi nedeniyle, kaynakların (bellek, işlem gücü vb.) daha verimli kullanılmasına olanak tanır. Adımlar sırasıyla birbirini etkileyebilir, bu da gereksiz kaynak tüketiminin önüne geçer.</li></ul><p>2. <strong><em>Test Edilebilirliğe Katkılar</em></strong></p><p>Pipeline pattern, her adımın bağımsız olarak test edilmesini mümkün kılar. Bu, yazılımın test edilebilirliğini artıran önemli bir özelliktir. Adım adım test etmenin sağladığı esneklik ve güvenilirlik şu şekildedir:</p><ul><li><strong>Bağımsız Testler</strong>: Her bir pipeline adımı, tek başına test edilebilir. Bu, her adımda oluşabilecek hataları izole etmeyi kolaylaştırır. Eğer bir hata oluşursa, hata sadece belirli bir adımda olabilir, dolayısıyla hata ayıklama işlemi daha hızlı ve verimli olur.</li><li><strong>Gerçekleştirilen İşlemlerin İzolasyonu</strong>: Her bir adımın bağımsız olarak test edilmesi, adımlar arasında herhangi bir dış etki olmadığından emin olmayı sağlar. Örneğin, bir veritabanı sorgusunun her adımda yapılması, bağımsız testlerin her adımın doğru şekilde çalıştığını garanti eder.</li><li><strong>Test Edebilirlik ve Sağlamlık</strong>: Adımların bağımsız test edilebilir olması, pipeline’ın daha sağlam olmasına katkı sağlar. Hangi adımın hata yaptığını anlamak, sadece belirli bir kısmı test ederek daha kolay hale gelir. Bu da yazılımın güvenilirliğini artırır.</li><li><strong>Refactoring ve Değişiklik Yönetimi</strong>: Pipeline’da yapılan değişiklikler, yalnızca etkilenen adımda test edilir, bu da yazılımın sürdürülebilirliğini artırır. Ayrıca, bir adımın refactor edilmesi gerektiğinde, tüm pipeline’ı değil sadece ilgili adımı test etmek yeterlidir.</li></ul><p>3. <strong>Örnek Senaryo:</strong></p><p>Eğer bir e-ticaret uygulamasında sipariş işleme pipeline’ı kullanılıyorsa, her adım şu şekilde bağımsız olarak test edilebilir:</p><ul><li><strong>Ödeme İşleme</strong>: Bu adım, ödeme işlemi için gerekli testleri yapabilir. Ödeme doğru işleniyor mu, yeterli bakiye var mı gibi testler yapılabilir.</li><li><strong>Stok Kontrolü</strong>: Stokların güncel durumunu kontrol etmek, stoktaki ürünlerin miktarını doğrulamak gibi işlemler test edilebilir.</li><li><strong>Sipariş Durumu Güncelleme</strong>: Siparişin durumu doğru şekilde güncelleniyor mu? Teslimat tarihi doğru giriliyor mu? Bu tür testler de bağımsız olarak yapılabilir.</li></ul><p>Her bir adımın bağımsız olarak test edilmesi, sürecin her aşamasında doğruluğu sağlar ve pipeline’ın genel güvenilirliğini artırır.</p><p>Pipeline pattern, özellikle test edilebilirlik açısından büyük avantajlar sunar. Her adımın bağımsız test edilmesi, yazılım geliştirme sürecini daha esnek, hızlı ve güvenilir hale getirir. Performans açısından da pipeline, optimize edilebilir ve paralel çalışmaya olanak tanır, böylece verimli bir işlem akışı sağlanır. Bu desen, özellikle karmaşık işlemleri izole etmek ve yönetmek için mükemmel bir yöntemdir.</p><h4>Pipeline Pattern’de Paralellik</h4><p>Paralellik, birden fazla adımın aynı anda çalıştırılmasını sağlayarak işleme sürelerini kısaltabilir ve verimliliği artırabilir. Pipeline’da paralellik sağlamak için, birbirinden bağımsız adımların paralel olarak çalıştırılması gerekir. Ancak, paralellik, her zaman uygun olmayabilir. Bu yüzden paralel adımların hangi durumlarda daha faydalı olduğunu anlamak önemlidir.</p><p><strong><em>Paralellik Ne Zaman Avantajlıdır?</em></strong></p><p>Paralellik, aşağıdaki durumlarda avantajlı olabilir:</p><ul><li><strong>Bağımsız Adımlar:</strong> Eğer pipeline’daki adımlar birbirinden bağımsızsa (yani bir adımın çıktısı, diğerinin girdi verisiyle ilişkili değilse), bu adımlar paralel olarak çalıştırılabilir. Bu durumda paralel işlem, işlem süresini ciddi şekilde kısaltabilir.</li><li><strong>CPU-bound İşlemler:</strong> Eğer adımlar hesaplama gerektiren işlemler (CPU-bound) yapıyorsa, paralel işleme bu adımların her birinin farklı bir iş parçacığında çalıştırılmasını sağlar ve işlem gücünden daha verimli yararlanır.</li><li><strong>I/O-bound İşlemler:</strong> Eğer adımlar I/O işlemleri (veri okuma/yazma, ağ çağrıları gibi) yapıyorsa, paralel işleme bu I/O işlemlerinin paralel bir şekilde yapılmasını sağlar. Bu da zaman kazandırabilir çünkü I/O işlemleri genellikle bekleme süresi içerir.</li><li><strong>Büyük Veri İşleme:</strong> Eğer pipeline, büyük veri kümeleri üzerinde işlem yapıyorsa, verilerin paralel işlenmesi işleri hızlandırır. Veri kümeleri bölünerek her biri paralel olarak işlenebilir.</li></ul><p><em>C#’ta Task ve Parallel ile Paralel Adımlar</em></p><p>C#’ta paralel adımları yönetmek için farklı araçlar mevcuttur. Bu araçlardan en yaygın olanları <strong>Task</strong> ve <strong>Parallel</strong> sınıflarıdır. Her iki sınıf da paralel işlemeyi yönetmek için kullanılır, ancak kullanım senaryoları farklıdır.</p><p><strong>1. Task ile Paralel İşlem</strong></p><p>Task, asenkron işlemler için uygun bir yapıdır. Task ile paralel çalışmayı şu şekilde gerçekleştirebiliriz:</p><ul><li>Her bir adım için bir Task oluşturup, Task.WhenAll ile tüm görevlerin tamamlanmasını bekleriz.</li></ul><p>Örnek :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14b530bf04700bbc35eb63b5120182f1/href">https://medium.com/media/14b530bf04700bbc35eb63b5120182f1/href</a></iframe><p>Bu örnekte, üç işlem paralel olarak başlatılır ve tüm adımlar tamamlanana kadar beklenir. Bu şekilde, her bir adımın tamamlanması için gerekli olan süreyi azaltabilirsiniz.</p><p><strong>2. Parallel ile Paralel İşlem</strong></p><p>Parallel sınıfı, aynı türdeki veri üzerinde işlem yaparken paralel işlemeyi yönetir. Özellikle büyük veri kümeleri üzerinde işlem yaparken, Parallel.ForEach gibi yöntemler kullanılır.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed09a1d97dcd18284a33d13226af89a4/href">https://medium.com/media/ed09a1d97dcd18284a33d13226af89a4/href</a></iframe><p>Bu örnekte, Parallel.ForEach her öğe üzerinde paralel olarak işlem yapar. Bu, veri koleksiyonlarını paralel olarak işlerken büyük veri setlerinde performansı artırabilir.</p><p><strong>Paralel Adımların Yönetimi</strong></p><p>Paralel işlem yapılırken bazı dikkat edilmesi gereken noktalar vardır:</p><ol><li><strong>Veri Paylaşımı:</strong> Paralel işlemler arasında veri paylaşımı dikkatlice yönetilmelidir. Ortak kaynaklara erişirken, veri tutarsızlıklarını önlemek için kilitleme mekanizmaları kullanılabilir.</li><li><strong>İşlem Sonrası Koşullar:</strong> Pipeline’daki paralel adımlar birbirinden bağımsız olsa bile, bazen adımların sıralı çalışması gerekebilir. Örneğin, bir adım diğerine veri sağlıyorsa, bu sıralı çalışmalıdır.</li><li><strong>Hata Yönetimi:</strong> Paralel adımlarda her adımda oluşabilecek hataların yönetimi önemlidir. Task.WhenAll kullanırken, hata yönetimini ele almak gerekebilir. Örneğin, bir görev başarısız olduğunda, tüm pipeline’ı durdurmak yerine hatalı adımı izole edebilirsiniz.</li><li><strong>Kaynak Kullanımı:</strong> Paralel işleme her zaman ek işlem gücü ve kaynak kullanımı gerektirir. Bu nedenle, paralel işlemin sistemin kaynaklarına nasıl etki ettiğini ve gereksiz kaynak kullanımını engellemek için uygun sayıda paralel işlem yapıldığını kontrol etmek önemlidir.</li></ol><p>Pipeline pattern’de paralellik sağlamak, işlemleri hızlandırabilir ve verimliliği artırabilir. Ancak paralel çalışmanın avantajları, adımların bağımsız olması ve işlem türünün uygun olması gibi durumlarla sınırlıdır. C#’ta Task ve Parallel gibi araçlarla paralel adımlar yönetmek, performans iyileştirmelerine olanak tanır. Bu araçların doğru şekilde kullanılması, daha hızlı ve verimli pipeline süreçleri elde edilmesini sağlar.</p><h4>Sonuç</h4><p>Pipeline pattern, modüler ve esnek iş akışları oluşturmanın yanı sıra, uygulamaların performansını artırabilir ve test edilebilirliğini iyileştirebilir. Özellikle veri işleme, doğrulama, dönüştürme gibi adımlarla ilerleyen süreçlerde, her bir adımın bağımsız olarak işlev görmesi ve sırasıyla birleştirilmesi sağlanarak karmaşık iş akışları daha yönetilebilir hale gelir.</p><p>Bu desenin uygulanabilirliği, genişletilebilirlik ve esneklik sunarken, her adımın bağımsız şekilde test edilmesi, yazılım geliştirme sürecinde hataların erken tespitini sağlar. Ayrıca, paralel işlem yapma imkanı da, büyük veri işleme ve CPU veya I/O-bound işlemlerin hızlandırılmasına olanak tanır.</p><p>Sonuç olarak, Pipeline pattern, özellikle sistemlerin sürdürülebilirliğini artırırken, yazılımın dayanıklılığını da pekiştiren bir yöntem olarak karşımıza çıkmaktadır. Kodun daha anlaşılır, esnek ve test edilebilir olmasını sağlarken, her bir adımda hata yönetimi ve performans optimizasyonu gibi konularda da ciddi avantajlar sunar.</p><p><em>Mit freundlichen Grüßen</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d6639ba90bf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devopsturkiye/net-coreda-pipeline-pattern-mod%C3%BCler-ve-esnek-i%CC%87%C5%9F-ak%C4%B1%C5%9Flar%C4%B1-olu%C5%9Fturma-7d6639ba90bf">.NET Core’da Pipeline Pattern: Modüler ve Esnek İş Akışları Oluşturma</a> was originally published in <a href="https://medium.com/devopsturkiye">Devops &amp; AI Türkiye☁️ 🐧 🐳 ☸️</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DotNet Unit Test Kalitesini Arttırmak]]></title>
            <link>https://karabuluthakan.medium.com/dotnet-unit-test-kalitesini-artt%C4%B1rmak-1eeb0010596d?source=rss-e3ddd311faec------2</link>
            <guid isPermaLink="false">https://medium.com/p/1eeb0010596d</guid>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[quality-software]]></category>
            <category><![CDATA[test-coverage]]></category>
            <category><![CDATA[strykernet]]></category>
            <dc:creator><![CDATA[Hakan Karabulut]]></dc:creator>
            <pubDate>Tue, 22 Feb 2022 19:48:30 GMT</pubDate>
            <atom:updated>2022-02-23T10:34:58.386Z</atom:updated>
            <content:encoded><![CDATA[<p>Geliştirme yaparken kurduğumuz algoritmanın nasıl davranış gösterdiğini anlayabilmek için Unit test yazmak çok elzem bir konu. Genellikle kodu ne kadar “cover” ettiğine bakmak bir kriter. Peki kodu büyük oranda “cover” eden bir test yazınca rahat hissetmeli miyiz? “Coverage” oranı bizim için yeterli bir kriter olmalı mı? Elbette ki “Coverage” bir kabullenme durumu ama test kalitesi hakkında kesin bilgi vermez. Bu yüzden sadece “Coverage” yeterli bir parametre olmamalı.</p><p>Örneklem için dört işlem yapan bir class yaratacağım. Toplama, çıkarma, çarpma işlemleri için önlem almamı gerektiren bir durum söz konusu değil, kullandığımız programlama dilinin operatörleri ile kolayca gerçekleştirebiliyoruz. Bölme işleminde bir takım matematiksel kontroller yapma ihtiyacı duyuyoruz. Çünkü biliyoruz ki bir sayı sıfıra bölme tanımsız bir işlemdir. Matematiksel işlemlerde sıfır bölü sayı “0” olarak kabul edilir, sıfır bölü sıfır ise belirsiz bir işlemdir. Bunlar kodumuzu geliştirirken dikkate alacağımız iş kuralları.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c692c34647cdd159864629b75672b95a/href">https://medium.com/media/c692c34647cdd159864629b75672b95a/href</a></iframe><p>Kodumuzu yazdık şimdi iş kurallarına göre unit testlerini de aşağıdaki gibi yazdığımızı düşünelim.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8e73049860e1c5328256d800ed8c076/href">https://medium.com/media/b8e73049860e1c5328256d800ed8c076/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y4SB7YD4hHuBDRVaiRZJ5A.png" /></figure><p>Çok başarılı bir “Coverage” görünüyor.</p><p>Testimizi test etmek için yardımcı bir araç kullanacağız. Benim tercihim Stryker.NET</p><p>Kurulum için test projesinin dizinine gelip aşağıdaki kodları yazmak gerekiyor.</p><p><em>dotnet new tool-manifest</em></p><p><em>dotnet tool install dotnet-stryker</em></p><p>Döküman üzerinden kuruluma bakmak isterseniz ilgili link aşağıdadır.</p><p><a href="https://stryker-mutator.io/docs/stryker-net/getting-started">Getting started | Stryker Mutator</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oh7xQ-ZLKLv_fMcB-dnIcA.png" /></figure><p>Kurulum aşamasından sonra Test projesinin yer aldığı dizine girip “dotnet stryker” yazmalısınız.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XYATjrv_ACf4RyqLcAq6xw.png" /></figure><p>Test projesinin olduğu dizin içinde “StrykerOutput” isimli bir klasör oluşacak ve burada “mutation-report.html” isimli bir dosya oluşacaktır.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tEp-U1pcxcEKZIerxv4Ylg.png" /></figure><p>Testini yazdığımız Class içindeki fonksiyonları kontrol etmek için açabiliriz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HKpYVWFRzl3h5cA0qsjSrw.png" /></figure><p>Yazdığımız kodun içeriğinde şöyle bir değişiklik yapsak:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7654dcbe80eeb1282d7c636ce142954b/href">https://medium.com/media/7654dcbe80eeb1282d7c636ce142954b/href</a></iframe><p>Bu durumda unit testlerimizi çalıştırdığımızda girmiş olduğumuz inline parametreler doğrultusunda testimiz gene başarılı olacaktır. Çünkü bizim kontrol ettiğimiz şey sonucun “0” dönmesidir. “Coverage” değerini arttıran ancak kör nokta yaratan bir durum var.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cfvyrUibqftxpmGehleacA.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebdb310970ed48a3f9137a1695eab65c/href">https://medium.com/media/ebdb310970ed48a3f9137a1695eab65c/href</a></iframe><p>Testteki “kör noktayı” kaldırmak için yeni bir parametre ekleyerek tekrar projeyi test ediyorum. Test proje dizininde tekrar “dotnet stryker” yazdığımızda ilgili method için Stryker tarafından “değiştirilebilir” hatasının kalktığını görebiliriz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lnM8w-gRgt35JCL13JeQfg.png" /></figure><p>Özetle kod için test yazmak çok önemli, test için “Coverage” değerini ölçmek iyi bir parametre ancak yeterli değil. Bu yüzden Stryker.Net gibi araçları kullanarak test kalitemizi arttırmak mümkün.</p><p>Proje kaynak kodlarına erişmek isterseniz:</p><p><a href="https://github.com/karabuluthakan/stryker">GitHub - karabuluthakan/stryker</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1eeb0010596d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[.Net Core Reflection Optimize]]></title>
            <link>https://karabuluthakan.medium.com/net-core-reflection-optimize-9f71200a2681?source=rss-e3ddd311faec------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f71200a2681</guid>
            <category><![CDATA[reflections]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[benchmark]]></category>
            <dc:creator><![CDATA[Hakan Karabulut]]></dc:creator>
            <pubDate>Fri, 18 Feb 2022 12:33:45 GMT</pubDate>
            <atom:updated>2022-02-23T12:06:55.308Z</atom:updated>
            <content:encoded><![CDATA[<p>Reflection denilince aklımıza gelen ilk şey “çok maliyetli” oluyor. Bazen Reflection iyi bir tercih olabiliyor. Örneğin private bir değişkeni değiştirmek ya da Runtime esnasında bir instance yaratıp property’lerini set etmek gibi ihtiyaçlarımız olabiliyor. Örnekler elbette çoğaltılabilir. Bu gibi ihtiyaçlarımız olduğunda gene aynı argümana sarılıp maliyet hesabı mı yapmalı? Peki bu maliyet (coast) bizim yazdığımız koddan kaynaklı olabilir mi?</p><p>İsterseniz birlikte daha optimize edilen bir reflection yazımı nasıl olabilir inceleyelim. Basit bir class yaratarak işe başlıyorum.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50b268a22394c26139ac5e5f9e761461/href">https://medium.com/media/50b268a22394c26139ac5e5f9e761461/href</a></iframe><p>Oluşturmuş olduğum class içinde bir tane public, bir de private property var. Private property’e class’ımın dışından erişim sağlamam mümkün değil. Ancak burada Reflection yardımımıza koşuyor.</p><p>Alışılagelmiş şekilde Reflection ile private değişkenimize şöyle erişim sağlayabiliriz; önce instance örneği alıp, type üzerinden propertyInfo’ya erişilir sonrasında property adını yazarak public ya da private olmasından bağımsız olarak erişim sağlayabiliyoruz. Koda döktüğümüzde aşağıdaki gibi bir halde olmasını bekleriz:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4feb8d5c0919de30c387ae79c7b62de9/href">https://medium.com/media/4feb8d5c0919de30c387ae79c7b62de9/href</a></iframe><p>Nasıl bir maliyet yaratmış olabilir Reflection bize? Buna benchmark testi ile bakalım:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*BMKQJCc0xSyjUdAWLcQ5iQ.png" /></figure><p>Yukarıdaki görselden anlaşılacağı üzere basit bir instance alıp property’e erişim sağlamamızın katbekat fazlası ile karşılaşıyoruz.</p><p>Biraz optimize etmeye başlayalım, mesela PropertyInfo kısmını memory’den okusa durum nasıl değişir? Kodu aşağıdaki gibi düzenliyorum:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06d85b24e37d42d4da6760961222014f/href">https://medium.com/media/06d85b24e37d42d4da6760961222014f/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*vj2DICemMZ0ujiQ2dwGIQw.png" /></figure><p>Eskisine nazaran bir iyileştirme söz konusu ama yeterince optimize olduğunu düşünemeyiz.</p><p>Nasıl bir iyileştirme yapabiliriz diye düşünürken yardımımıza Delegate koşuyor. Bir önceki optimize örneğinde memory’de property tutarak biraz iyileştirme yapmıştık. Şimdi bir delegate kullanarak kodumuzu aşağıdaki gibi düzenleyebiliriz:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d58769d9856d338d312fa666d9f80b18/href">https://medium.com/media/d58769d9856d338d312fa666d9f80b18/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*QuGZmchaHI1cOeZmDIlN0g.png" /></figure><p>Yukarıdaki metriklere bakınca sonucun oldukça başarılı olduğu kanaatindeyim.</p><p>Umarım faydalı bir makale olmuştur, proje koduna erişmek isterseniz:</p><p><a href="https://github.com/karabuluthakan/reflection">GitHub - karabuluthakan/reflection</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f71200a2681" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dotnet Object Mapping Benchmark]]></title>
            <link>https://karabuluthakan.medium.com/dotnet-object-mapping-benchmark-ed3062794bd3?source=rss-e3ddd311faec------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed3062794bd3</guid>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[automapper]]></category>
            <category><![CDATA[objectmapper]]></category>
            <category><![CDATA[mapster]]></category>
            <category><![CDATA[mapping]]></category>
            <dc:creator><![CDATA[Hakan Karabulut]]></dc:creator>
            <pubDate>Mon, 03 Jan 2022 22:38:41 GMT</pubDate>
            <atom:updated>2022-01-03T22:38:41.901Z</atom:updated>
            <content:encoded><![CDATA[<p>Crud işlemi yapmak işimizin doğasında var. Peki bunu yaparken doğrudan DbModel’ine karşılık gelen class’ları mı her yerde doğrudan kullanıyoruz, elbette ki hayır. Bunun yerine use-case’e göre veri korunaklığı görevini üstlenen Data Transfer Object (DTO) ile işlemlerimizi gerçekleştiriyoruz. Bu durum beraberinde object dönüştürme işlemlerini de getirmektedir.</p><p>Peki bu işlemleri yapmakta hangi yöntemi/paketi tercih etmek gerekiyor. Sıklıkla kullanılan AutoMapper mı? Manuel olarak map’leme mi yapmalıyız? Yoksa bu işi daha hızlı yapabilen başka şeyler var mı?</p><p>Bu makalede ExpressMapper, AutoMapper, Mapster ve static map işlemlerinin hangisinin daha hızlı çalıştığını Benchmark testi ile anlamaya çalışacağız.</p><p>Örnekleme için basit bir entity modeli oluşturarak işe başlayalım.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ef42f3603948eba614d3dbebb462768/href">https://medium.com/media/1ef42f3603948eba614d3dbebb462768/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8522055202d45d36bfb01ed7730badb4/href">https://medium.com/media/8522055202d45d36bfb01ed7730badb4/href</a></iframe><p>Entity’leri ve Dto’ları basit anlamda oluşturduğumuza göre Map işlemlerini yapacak classlarımızı yaratabiliriz.</p><p>AutoMapper için :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0c74ad04ffbef84aae0a8aea6510daf/href">https://medium.com/media/b0c74ad04ffbef84aae0a8aea6510daf/href</a></iframe><p>Mapster için oluşturduğum Config :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a97d3251d8eb36d867d4c9002480994/href">https://medium.com/media/7a97d3251d8eb36d867d4c9002480994/href</a></iframe><p>Map için örnek bir dataya ihtiyacımız olacak. Onu da aşağıdaki gibi örnekledim:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/676323d047617d29deb58dfc1664d6cd/href">https://medium.com/media/676323d047617d29deb58dfc1664d6cd/href</a></iframe><p>Gelelim map işlemlerini yapacak kısma.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/641ca8c95dc62a1671c92b59f7d98648/href">https://medium.com/media/641ca8c95dc62a1671c92b59f7d98648/href</a></iframe><p>Benchmarks’ları da aşağıdaki gibi örnekledim.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4553077b66f797f8a61759cceef7b2f8/href">https://medium.com/media/4553077b66f797f8a61759cceef7b2f8/href</a></iframe><p>Peki sonuçlar sizce nasıl oldu dersiniz?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ozH7Y9dHbBtXODup_9wVfQ.png" /></figure><p>Mapster basit anlamda kullanılınca gayet iyi sonuçlar vermektedir. İlerleyen zamanda Mapster kütüphanesi ile ilgili ayrıca bir makale de hazırlamayı planlıyorum, makaleyi yazdığım zaman linkini buraya ekleyeceğim.</p><p>Kaynak kodlara erişmek isterseniz :</p><p><a href="https://github.com/karabuluthakan/dotnet-object-mapping">GitHub - karabuluthakan/dotnet-object-mapping</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed3062794bd3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Asp.Net Core Api Pagination]]></title>
            <link>https://karabuluthakan.medium.com/asp-net-core-api-pagination-42fbdae760f7?source=rss-e3ddd311faec------2</link>
            <guid isPermaLink="false">https://medium.com/p/42fbdae760f7</guid>
            <category><![CDATA[pagination]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[generic-programming]]></category>
            <dc:creator><![CDATA[Hakan Karabulut]]></dc:creator>
            <pubDate>Mon, 29 Jun 2020 14:27:52 GMT</pubDate>
            <atom:updated>2020-06-29T14:27:52.491Z</atom:updated>
            <content:encoded><![CDATA[<p>Bu makalede dotnet core rest api listeleme endpointlerinde sayfalama işlemlerini örnekle açıklamaya çalışacağım.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SMVoIt_Dp7dPyVsIUTiNug.png" /></figure><p>Öncelikle işe Api dönüş tiplerini soyutlama ile başlıyorum. Bu doğrultuda birden fazla result tipinde base olarak kullanacağım IResult olarak isimlendirdiğim temel interface’i oluşturarak başladım. Geriye kalanı kod anlatsın =)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bd1443f7c05b0b90a15af0c9bab9873/href">https://medium.com/media/1bd1443f7c05b0b90a15af0c9bab9873/href</a></iframe><p>Sayfalama için kullanacağım result için;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31e15539167ff24deb3d9d69555030d9/href">https://medium.com/media/31e15539167ff24deb3d9d69555030d9/href</a></iframe><p>Sayfalama olmadan geri döneceğim data için kullandığım interface;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf0aec4224653838e6d455e83a26111f/href">https://medium.com/media/bf0aec4224653838e6d455e83a26111f/href</a></iframe><p>Gelelim bunları implemente eden concrete sınıflara. Bunların içeriğini de aşağıdaki gibi oluşturdum.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95689eec9d546f4a2608b8ac9d015acb/href">https://medium.com/media/95689eec9d546f4a2608b8ac9d015acb/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0a043232eac9ac3c06d1fbf1c4a03e1/href">https://medium.com/media/a0a043232eac9ac3c06d1fbf1c4a03e1/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5a7b31495b1b315ededfaab8b2d4088/href">https://medium.com/media/c5a7b31495b1b315ededfaab8b2d4088/href</a></iframe><p>Sayfalama için kullanacağım bir yardımcı model’e ihtiyacım var, bunun için;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1df02e3e689680ed97b43ec00a943d2f/href">https://medium.com/media/1df02e3e689680ed97b43ec00a943d2f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d917e70d50b75a1311ec5f7a7268d68/href">https://medium.com/media/3d917e70d50b75a1311ec5f7a7268d68/href</a></iframe><p>Sayfalamada Uri kullanacağım için yardımcı bir servise ihtiyacım var. Bunun için;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0b260e48c8e4b15762b938eec6a5c22/href">https://medium.com/media/c0b260e48c8e4b15762b938eec6a5c22/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c8551a2e842a9dd068e482612e9856a/href">https://medium.com/media/8c8551a2e842a9dd068e482612e9856a/href</a></iframe><p>HttpContextAccessor üzerinden kullandığım extension methodlarım;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c27183dc3d926e5ebf96e77d01ffb827/href">https://medium.com/media/c27183dc3d926e5ebf96e77d01ffb827/href</a></iframe><p>Servis katmanında kullanmak için PaginationDataResult için bir yardımcı method daha eklemesi yaptım;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3384a60c64b1be67ec6ba8fb11167373/href">https://medium.com/media/3384a60c64b1be67ec6ba8fb11167373/href</a></iframe><p>Servis katmanı için şöyle bir interface kullanıyorum, sayfalama vb işlerimi de doğrudan servis içinde halletmeyi tercih ediyorum.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4009c8a6bd941e3fd4ae12a984725b59/href">https://medium.com/media/4009c8a6bd941e3fd4ae12a984725b59/href</a></iframe><p>Yukarıdaki interface’i implemente eden sınıfın içeriğini aşağıdaki gibi doldurdum.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/998f82ece2c76680847b5debc5748af4/href">https://medium.com/media/998f82ece2c76680847b5debc5748af4/href</a></iframe><p>Endpoint düzeyinde kullanmak için öncelikle DI’ları Startup.cs içinde tanımlamalıyım. Bunun için;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df34a2955ed3880d1f4141be9ec667e0/href">https://medium.com/media/df34a2955ed3880d1f4141be9ec667e0/href</a></iframe><p>Artık endpoint’leri yazmaya başlayabilirim. Bu örnekte hep aynı tür endpoint’ler kullanacağım için generic bir yapı kullanmayı tercih ettim.</p><p>Controller için yazmış olduğum extension;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c98c276fc83cf598b483bc1a94fb9987/href">https://medium.com/media/c98c276fc83cf598b483bc1a94fb9987/href</a></iframe><p>Generic oluşturduğum Controller ise;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d83246cfd9abaa48a324c987ef16ae5a/href">https://medium.com/media/d83246cfd9abaa48a324c987ef16ae5a/href</a></iframe><p>Endpoint’lerim artık aşağıdaki gibi bir örneğe dönüştü:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04651b81374a502b563897134bc812a3/href">https://medium.com/media/04651b81374a502b563897134bc812a3/href</a></iframe><p>Son durumda dönen result örneği :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HF3AOThABD_vNMPr1UgqsA.png" /></figure><p>Api tarafında sayfalanmış halde dönen data UI kısmında iş yükünü alacaktır.</p><p>Projenin tamamına erişmek isterseniz:</p><p><a href="https://github.com/karabuluthakan/DotnetCoreApiPagination">karabuluthakan/DotnetCoreApiPagination</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42fbdae760f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Asp.Net Core Api ile OData Kullanımı]]></title>
            <link>https://medium.com/devopsturkiye/asp-net-core-api-ile-odata-kullan%C4%B1m%C4%B1-9f941abedcc3?source=rss-e3ddd311faec------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f941abedcc3</guid>
            <category><![CDATA[odata]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[asp-net-web-api]]></category>
            <dc:creator><![CDATA[Hakan Karabulut]]></dc:creator>
            <pubDate>Sat, 16 May 2020 15:42:18 GMT</pubDate>
            <atom:updated>2020-05-18T08:52:40.752Z</atom:updated>
            <content:encoded><![CDATA[<p>Bu makalede OData hakkında bilgi verip, dotnet projesinde uygulaması ile ilgili örnekleme yapmaya çalışacağım.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ojQ9l8Hvf948XdrokTmDFg.jpeg" /></figure><h4>OData Nedir?</h4><p>Open Data Protocol olarak da isimlendirebileceğimiz OData, veri kaynaklarını REST url üzerinden sorgulama protokolüdür. Microsoft tarafından 2007 yılında geliştirilmeye başlanmıştır. Api uygulamalarında kullanılmakatadır.</p><p>OData ile yapacağınız sorguları client tarafına bırakarak, complex ya da tailored endpointler geliştirme maliyetinden kurtulabilirsiniz.</p><p><strong>OData action dönüş tipinin IQueryable olması daha performanslı sorgulamalar yapmamızı sağlar.</strong></p><h4>Projeye Dahil Edilmesi</h4><p><a href="https://www.nuget.org/packages/Microsoft.AspNetCore.OData/">Microsoft.AspNetCore.OData 7.4.0</a></p><p>Nuget üzerinden paket projeye dahil edilir.</p><p>ConfigureServices kısmında aşağıdaki gibi servis katmanına eklememizi yapıyoruz.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b0843c5866fcc24b90bb2024b72d52a/href">https://medium.com/media/3b0843c5866fcc24b90bb2024b72d52a/href</a></iframe><p>Middleware olarak ekleme için Configure içinde aşağıdaki gibi bir ayarlama yapılmalıdır.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5aff29ea5ba2124fac3b67fda8d24a8f/href">https://medium.com/media/5aff29ea5ba2124fac3b67fda8d24a8f/href</a></iframe><p>Yukarıda yazıklarımızı inceleyelim;</p><ul><li>OData entity’e [EntitySetName]Controller olarak erişim yaptığı için Controller adı olarak ne verdiyeseniz EntitySet içeriğine de böyle bir isimlendirme yapmalısınız.</li><li>Birinci “odata” routeName olarak veriyoruz.</li><li>İkinci “odata” ise <a href="http://www.your_awesome_domain.com/odata/entityName">www.your_awesome_domain.com/odata/entityName</a> sorgulama yapacağımız prefix’i tanımlamak için veriyoruz.</li><li>builder.GetEdmModel() ise EntityDataModel’in kısaltmasıdır. Model’in property’lerine ve navigation property’lerine erişim için kullanılır. Database üzerinden alınan sorguları entity model’ine dönüştürür.</li></ul><p>Şimdi Controller’ları oluşturmaya başlayabiliriz.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a442466e4482b068d82025d78b80935/href">https://medium.com/media/8a442466e4482b068d82025d78b80935/href</a></iframe><p>Bir controller’in OData ile ilişkisini kurmak için <strong>ODataController</strong>’dan türetilmesi yeterlidir. Dikkat ettiyseniz ApiController ve Route ile ilgili tanımlamalar yer almıyor, OData bizim yerimize bu işlemleri üstleniyor.</p><p>Odata’nın kullanımı için Controller bazında bir kaç şeye daha dikkat etmemiz gerekmektedir.</p><ul><li>OData Controller içinde method isimlendirmesi <strong>Get() </strong>ya da<strong> GetCities() </strong><em>(entity’nin çoğul hali) </em>şeklinde olmalıdır.</li><li>OData Controller’a sorgulama özelliğini kazandırmak için method üzerine <strong>[</strong>EnableQuery<strong>] </strong>attribute konulmalıdır.</li></ul><p>OData’nın projemize dahil edilmesi bu kadar kolay =)</p><p><strong>OData Metadata (</strong><a href="http://www.your_awesome_domain.com/odata/$metadata"><strong>$metadata</strong></a><strong>)</strong></p><p>OData’nın kullandığı entity’ler hakkında bilgi içeren bir nevi dökümantasyonuna erişmek için <a href="http://www.your_awesome_domain.com/odata/$metadata">www.your_awesome_domain.com/odata/<strong>$metadata</strong></a><strong> </strong>yazmanız yeterlidir.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38e8b86d0d818b9bac97aad786b35bf2/href">https://medium.com/media/38e8b86d0d818b9bac97aad786b35bf2/href</a></iframe><p>OData ile Swagger birlikte kullanmanız pek mümkün değil, onun için Metadata dökümantasyon ihtiyacını karşılıyor.</p><p>OData ile sorgulama nasıl yapılır bunu incelemeye başlayabiliriz artık.</p><h4>OData Query Options</h4><p>Query Options’lar server üzerinden dönecek data miktarını kontrol etmek için kullandığımız seçeneklerdir. Üç parça olarak inceleyebiliriz. Birinci kısım base url (<em>your_awesome_url/odata), </em>ikinci kısım resource (cities) yani controller, üçüncü kısım ise filtre yapacağımız alan (<strong>$select=Name</strong>) olarak sınıflandırılabilir.</p><p>Query Options yazarken query string key value olduğu için resource sonrasında <strong>?</strong> işareti sonrası mutlaka <strong>$ </strong>işareti kullanılmalıdır.</p><p><em>your_awesome_url/odata</em>/cities?<strong>$select=Name,…</strong></p><p>Query Options kullandığınızda dönen data her zaman iki parçadan oluşur;</p><p><strong>1-</strong> “@odata.context”: “http://localhost:5000/odata/$metadata#Cities&quot;,</p><p>Yukarıdaki yapı ile resource metadata bilgilerini içeren bir bilgi döner.</p><p><strong>2-</strong> “value”: [] içinde ise data döner. Tek bir değer almaya çalışsanız da value içindeki array içinde geri dönüş olur.</p><h4><strong>$Select</strong></h4><p>Entity üzerinden dönecek propertyleri filtrelemek için kullanılır. Hangi propertylere ihtiyacınız varsa onları alma olanağı sunar. Kullanabilmek için Startup içinde şöyle bir ayarlama yapmalıyız.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e9694912632d9443ad313a117683397/href">https://medium.com/media/0e9694912632d9443ad313a117683397/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kLl64nZhIbagG7qevL_bgQ.png" /><figcaption>Filtresiz request ile dönen data</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R4McPpjtCiwtMCY90Rq31g.png" /><figcaption>Filtre ile dönen data</figcaption></figure><h4><strong>$Expand</strong></h4><p>Sorgulama yaptığımız entity’nin navigation property’si varsa o entity’inin de datalarını alabilme olanağı sunar. $expand yazıp resource entity’nin bağlı bulunduğu navitagion property’i yazarak dataya erişim sağlarız. Tabii bunu da kullanabilmek için aşağıdaki gibi bir ayarlama yapmamız lazım;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6dbc05f141065b3c936faec2ac2425df/href">https://medium.com/media/6dbc05f141065b3c936faec2ac2425df/href</a></iframe><p><em>your_awesome_url/odata</em>/cities?<strong>$expand=</strong>country</p><p>Resource entity’nin başka bir navigation property’si varsa ve bunu da sorguda almak istiyorsanız “,” ile ayrırarak sorgulama yapabilirsiniz.</p><p><em>your_awesome_url/odata</em>/cities?<strong>$expand=</strong>country,other_navigation_propery</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w1Vyd-tjLKkhaBOA0Bb_5A.png" /></figure><p>Expand ile dönen data üzerinde de filtreleme yapabilme olanağımız var. Bunun için parantez içinde $select ile sorgulama yapabilirsiniz</p><p><em>your_awesome_url/odata</em>/cities<strong>$expand=</strong>country($select=name,alpha2code)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sv-QcGHw4HR0kxalUNpRLQ.png" /></figure><h4><strong>$OrderBy</strong></h4><p>Entity’nin bir ya da birden fazla property’sine göre sıralama işlemi yapmak için kullanılır. Tabii bunu da kullanabilmek için aşağıdaki gibi bir ayarlama yapmamız lazım;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/159e516d93df9d7d3c3c4f08c32c6266/href">https://medium.com/media/159e516d93df9d7d3c3c4f08c32c6266/href</a></iframe><p><em>your_awesome_url/odata</em>/countries?$orderBy=regionId desc</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UhOlYEEuXn17EF7snxsHJg.png" /></figure><p>İkinci bir propery ile sıralama yapmak için “,” ile ayırıp desc ya da asc yazarak soruguyu oluşturabiliriz.</p><p><em>your_awesome_url/odata</em>/countries?$orderBy=regionId desc, name asc</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hVXmfVtALOaGXDHXTNx7FQ.png" /></figure><h4><strong>$Top</strong></h4><p>Bir dizinden kaç tane item almak istiyorsak kullanabiliriz.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/797aa879234d83242d3f8db46a26a82b/href">https://medium.com/media/797aa879234d83242d3f8db46a26a82b/href</a></iframe><p><em>your_awesome_url/odata</em>/cities?$top=2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8jk5E79TY187tMJ2REl_AQ.png" /></figure><h4><strong>$Skip</strong></h4><p>Adından da anlaşılacağı gibi atlama için kullanılır. Top keyword’ü ile kullanılırsa sayfalama yapabilirsiniz. Endpoint ile iligili bir ayarlama yapmamıza gerek yok, default olarak geliyor.</p><p><em>your_awesome_url/odata</em>/cities?$skip=2</p><p><em>your_awesome_url/odata</em>/cities?$skip=0&amp;$top=3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9yzftipmvvtagnEFn0y02g.png" /></figure><p><strong>Birden fazla filtreyi bir arada kullanmak isterseniz &amp; ile filtreleri birleştirebilirsiniz.</strong></p><h4><strong>$Count</strong></h4><p>Dönen datanın miktarını belirtir.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf679e1990b4e7218c3f843370d2cf4f/href">https://medium.com/media/cf679e1990b4e7218c3f843370d2cf4f/href</a></iframe><p><em>your_awesome_url/odata</em>/cities?$count=true</p><p>“@odata.count” ile datanın kaç tane olduğunu gösterir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6ychMsXIsG0rBkGAFYmWCA.png" /></figure><h4><strong>$Filter</strong></h4><p>Filtreleme yapmak için kullanılır. Logical operations, arithmetic operations ve functions olmak üzere 3 başlıkta incelemek mümkündür;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d11afbb935f33d86a2eb8eab01a69c0e/href">https://medium.com/media/d11afbb935f33d86a2eb8eab01a69c0e/href</a></iframe><p><strong>Logical Operators</strong></p><p><strong>eq :</strong> Equal kısaltılmasıdır.</p><p><strong>ne :</strong> Not Equal kısaltılmasıdır.</p><p><strong>gt :</strong> Greather than kısaltılmasıdır.</p><p><strong>ge :</strong> Greather equal kısaltılmasıdır.</p><p><strong>lt :</strong> Less than kısaltılmasıdır.</p><p><strong>le :</strong> Less equalkısaltılmasıdır.</p><p><em>your_awesome_url/odata</em>/cities?$filter=name eq ‘İstanbul’</p><p><strong>Arithmetic Operators</strong></p><p><strong>add</strong> : Adding kısaltmasıdır, toplama işlemi için kullanılır.</p><p><strong>sub </strong>: Subtraction kısaltmasıdır, çıkarma işlemi için kullanılır.</p><p><strong>mul </strong>: Multiplication kısaltmasıdır, çarpma işlemi için kullanılır.</p><p><strong>div </strong>: Division kısaltmasıdır, bölmeişlemi için kullanılır.</p><p><em>your_awesome_url/odata</em>/products?$filter=stock add 100 eq 500</p><p>Stock değeri 500&#39;e eşit olanlara 100 ekler.</p><p><strong>Functions</strong></p><p><strong>endswith </strong>: Herhangi bir string ifadenin sonunun iligili filter ile bitenini getirmek için kullanılır.</p><p><strong>startswith </strong>: Herhangi bir string ifadenin başlangıcının iligili filter ile başlayanını getirmek için kullanılır.</p><p><strong>length </strong>: Herhangi bir string ifadenin uzunluğu ile ilgili karşılaştırma yapılabilir.</p><p><strong>indexof </strong>: Herhangi bir string ifadenin içinde bir harfin hangi index’te yer aldığı ile sorgulama yapmak için kullanılır.</p><p><strong>trim </strong>: Herhangi bir string ifadenin sağındaki ve solundaki boşluklardan arındırmak için kullanılır.</p><p><strong>year </strong>: Tarih bilgisi içeren field üzerinden yıl bilgisine göre filtreleme için kullanılır.</p><p><strong>month </strong>: Tarih bilgisi içeren field üzerinden ay bilgisine göre filtreleme için kullanılır.</p><p><strong>day </strong>: Tarih bilgisi içeren field üzerinden gün bilgisine göre filtreleme için kullanılır.</p><p><em>your_awesome_url/odata</em>/cities?$filter=year(CreatedDate) eq 2020</p><h4>OData/Attribute</h4><p>OData’nın controller düzeyinde isimlendirme kurallarından daha önce bahsetmiştik. Şimdi biraz daha fazla bu konuları inceleyelim, istersek custom route ve isimlendirmeleri nasıl yapabileceğimize bakalım.</p><p>Id alanı ile sorgulama yapmak istersek default olarak şöyle olmalıdır;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07758d05a8f5ec90bb7f62466d53cd70/href">https://medium.com/media/07758d05a8f5ec90bb7f62466d53cd70/href</a></iframe><p><em>your_awesome_url/odata</em>/cities(40)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pleGjanc2DGXd82OjjbJ4Q.png" /></figure><p>Şimdiye kadar gördüğümüz tüm filtreleme yöntemlerini de sorguya dahil edebiliriz.</p><p><strong>ODataRoute</strong></p><p>Custom isimlendirme yapmak istersek OData’ya kullanıdğımız ismi ODataRoute attribute ile bildiriyoruz.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d185409e5d0876c6c19b512fd5a0263/href">https://medium.com/media/6d185409e5d0876c6c19b512fd5a0263/href</a></iframe><p><strong>ODataRoutePrefix</strong></p><p>ODataRoute ile custom isimlendirme yaparken daima <strong>[</strong>ODataRoute(“cities({itemId})”)] controller isimlendirmesi yapmamız gerekiyor. Bu tekrarı engellemek için Controller class’ının başına <strong>[</strong>ODataRoutePrefix(“cities”)] eklemesi yaparsak tekrar tekrar Controller ismini yazmamıza gerek kalmaz, <strong>[</strong>ODataRoute(“({itemId})”)] olarak yazabiliriz.</p><p><strong>OData Pagination</strong></p><p>OData ile sayfalama yapmak gerçekten çok kolay =)</p><pre><strong>[</strong>EnableQuery(PageSize = 10)<strong>]</strong></pre><p>EnableQuery attribute içine kaç item yer almasını istiyorsanız PageSize ile belitmeniz yeterli.</p><p><em>your_awesome_url/odata</em>/cities</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n2CBQbd4vPqMFZVVcgl45w.png" /></figure><p>Dikkat ederseniz gelen data dışında</p><p>“@odata.nextLink”: “http://localhost:5000/odata/cities?$skip=10&quot;</p><p>gibi bir link var. Buna tıkladığınızda bir sonraki sayfayı gösterecektir.</p><h4><strong>OData Action/Function</strong></h4><p>Bir method içinde complex type ya da fazla parametre alması durumunda Action ya da Function kullanılabilir. İkisi arasındaki fark; Action Post ile sorgulama için kullanılır. Function ise Get sorgulaması ile kullanılır. Action ya da Function kullanmak için tanımlama yaptığınız isimle bire bir aynı endpointinizin olması gerekmektedir.</p><p><strong>OData Action (No Parameter)</strong></p><p>Kullanmış olduğum endpointler için custom bir method yazacağım. Geriye string bir data dönecek. Bunun için County modelini kullanacağım ve geriye ülke adı ve sembolü dönen basit bir result dönecek. Startup içinde aşağıdaki gibi bir tanımlama yapıyorum;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbc8bbbbbde6cc54c0764d47c697a27c/href">https://medium.com/media/fbc8bbbbbde6cc54c0764d47c697a27c/href</a></iframe><p>Endpoint olarak belirtmiş olduğum isimlendirmeyi kullanmam lazım. Action yazdığımız için Post ile istek yapmamız gerekmektedir.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/807146e53281525b5858e8d561b2c619/href">https://medium.com/media/807146e53281525b5858e8d561b2c619/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJ14jP4z_WRK21ofnGVqBw.png" /></figure><p><strong>OData Action (With Parameter)</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0eb06f9edc043c9ace6588d93035cdc/href">https://medium.com/media/b0eb06f9edc043c9ace6588d93035cdc/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9cead8e7662c64d2155bc4fe004c8a33/href">https://medium.com/media/9cead8e7662c64d2155bc4fe004c8a33/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*28EOFI3jD5qtLDPy5GZSWw.png" /></figure><p><strong>OData Action Multiple Parameter</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d842fab4f6919ba0d814a644d1e614b4/href">https://medium.com/media/d842fab4f6919ba0d814a644d1e614b4/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a8f4b5d26656d564f7acfadcc465a8b/href">https://medium.com/media/1a8f4b5d26656d564f7acfadcc465a8b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ialJb_2sWxzltF-b1AEY4Q.png" /></figure><p><strong>OData Action ComplexType</strong></p><p>Basit bir model oluşturuyorum;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02d50eb59736f35b37f22a4848800b9d/href">https://medium.com/media/02d50eb59736f35b37f22a4848800b9d/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4472b427ac8cacbb18dd6960ca8fe5f4/href">https://medium.com/media/4472b427ac8cacbb18dd6960ca8fe5f4/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9ad93a819a5d294a5724c39ebf521e1/href">https://medium.com/media/f9ad93a819a5d294a5724c39ebf521e1/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WJUUiFI6HJO6DtVCjbttKw.png" /></figure><p><strong>OData Function</strong> <strong>(No Parameter)</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e4984248d2b2f971ba38589c089a345/href">https://medium.com/media/3e4984248d2b2f971ba38589c089a345/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4372b3da4c3ee3315dcd2c827a8e1f47/href">https://medium.com/media/4372b3da4c3ee3315dcd2c827a8e1f47/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LnPPNJSeieXZIX457RZeMw.png" /></figure><p><strong>OData Function</strong> <strong>(With Parameter)</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6057949a58240b7d72cddd4fcda3992a/href">https://medium.com/media/6057949a58240b7d72cddd4fcda3992a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ad55d7cd2fef05c0648bad72123cf4c/href">https://medium.com/media/8ad55d7cd2fef05c0648bad72123cf4c/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q5esiFjJtggunQRwD0hnlg.png" /></figure><p><strong>OData UnBound Function/Action</strong></p><p>OData, bir entity’e bağlı olmadan da Function ya da Action oluşturmamıza olanak sağlamaktadır.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02fb9b6e3a0d7845a16a02e991cc61b2/href">https://medium.com/media/02fb9b6e3a0d7845a16a02e991cc61b2/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a1300becbc57c9874b10de29c333368/href">https://medium.com/media/5a1300becbc57c9874b10de29c333368/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v0yUciQXlG7MV8kIcYZU-Q.png" /></figure><p>Son olarak şunu hatırlatalım, endpoint bazında OData ile ilgili engellemeler ya da izinler vermek isterseniz EnableQuery attribute içinden bunları yapma olanağınız vardır. Attribute’ü karıştırdığınızda çok rahatlıkla görebilirsiniz diye teker teker izah etmeye gerek duymadım.</p><p>Ayrıca entity düzeyinde de $select, $filter vb engellemeler ya da izinler verme olanağınız bulunmaktadır.</p><p>OData’nın Swagger ile birlikte kullanımı olmadığı için ben sadece tüm datayı listelediğim (GetAll gibi) ya da id ile tek bir datayı gösterdiğim (GetById gibi) endpointlerde kullanıyorum. Bu endpointlerde de fazlasıyla iş çıkardığı için tercih sebebim oluyor.</p><p>Ayrıca piyasadaki rakibi GraphQL ile kıyaslandığında çok daha kısa sürede öğrenilen ve uygulamaya geçirmesi çok çok daha kolay olduğu için tercih ediyorum.</p><p>Projenin kaynak kodlarına erişmek isterseniz;</p><p><a href="https://github.com/karabuluthakan/DotnetCoreOData">karabuluthakan/DotnetCoreOData</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f941abedcc3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devopsturkiye/asp-net-core-api-ile-odata-kullan%C4%B1m%C4%B1-9f941abedcc3">Asp.Net Core Api ile OData Kullanımı</a> was originally published in <a href="https://medium.com/devopsturkiye">Devops &amp; AI Türkiye☁️ 🐧 🐳 ☸️</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Asp.Net Core MongoDb Generic Repository]]></title>
            <link>https://medium.com/devopsturkiye/asp-net-core-mongodb-generic-repository-8afa49e742dd?source=rss-e3ddd311faec------2</link>
            <guid isPermaLink="false">https://medium.com/p/8afa49e742dd</guid>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[repository-pattern]]></category>
            <category><![CDATA[generic-programming]]></category>
            <category><![CDATA[mongodb]]></category>
            <dc:creator><![CDATA[Hakan Karabulut]]></dc:creator>
            <pubDate>Fri, 24 Apr 2020 22:13:40 GMT</pubDate>
            <atom:updated>2020-04-25T20:00:42.608Z</atom:updated>
            <content:encoded><![CDATA[<p>Merhaba, bu makalede Generic Repository pattern’in MongoDb implementasyonunu örnekle açıklamaya çalışacağım.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*SgAzMrMgr2-stCLDMjxjrw.jpeg" /></figure><p>Öncelikle database modelleri için kullanacağım base interface oluşturarak başlıyorum.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76d22961705ac378de2e10493b4b6baf/href">https://medium.com/media/76d22961705ac378de2e10493b4b6baf/href</a></iframe><p>MongoDb’yi kullanabilmek için MongoDriver paketini projemize dahil etmeliyiz;</p><p><a href="https://www.nuget.org/packages/mongodb.driver">MongoDB.Driver 2.10.3</a></p><p>Mongo modelleri için kullanılacak base model;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fde9848de0d52aaa199184002f8fda83/href">https://medium.com/media/fde9848de0d52aaa199184002f8fda83/href</a></iframe><p>Modeller için kullanılacak abstract yapıdan sonra artık repository oluşturabiliriz;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75b8cb61db320bafa90ce70837d4bf6d/href">https://medium.com/media/75b8cb61db320bafa90ce70837d4bf6d/href</a></iframe><p>MongoDb ile ilgili connectionString ve db ismini appsettings.json içinden okumak için yardımcı model olarak;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1d8e4204cb3127e3b687d9389b2f5c0/href">https://medium.com/media/e1d8e4204cb3127e3b687d9389b2f5c0/href</a></iframe><p>Şimdi Repository pattern’i mongo için uygulayacağımız base repository’i oluşturabiliriz;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f50957da42e0b2568385270e1c892547/href">https://medium.com/media/f50957da42e0b2568385270e1c892547/href</a></iframe><p>Örnek için kullanacağım model;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c4f95d0f107f0a3eea7eaa2975bbaa1/href">https://medium.com/media/3c4f95d0f107f0a3eea7eaa2975bbaa1/href</a></iframe><p>Şimdi bu model için DataAccess tarafında oluşturacağımız soyut (abstract) ve somut (concrete) sınıflar;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed4b0b2aad4ff7267071e8b6b89eee4c/href">https://medium.com/media/ed4b0b2aad4ff7267071e8b6b89eee4c/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52f0501047fe89ad5b6614f89a132637/href">https://medium.com/media/52f0501047fe89ad5b6614f89a132637/href</a></iframe><p>Startup içinde daha önceden oluşturduğumuz MongoDbSettings modelini appsettings.json içindeki değerlerle doldurmak için bir extension method yazıyorum;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22316ca73ab89090ce662317423c37a8/href">https://medium.com/media/22316ca73ab89090ce662317423c37a8/href</a></iframe><p>Startup içinde aşağıdaki gibi servisleri eklemeliyiz;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b671eb8d6120196d3b3e484fd031d34c/href">https://medium.com/media/b671eb8d6120196d3b3e484fd031d34c/href</a></iframe><p>appsettings.json içinde configuration içeriklerini girmemiz gerekiyor;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb77aefde4c9cafe92c31d1a566c2bbc/href">https://medium.com/media/cb77aefde4c9cafe92c31d1a566c2bbc/href</a></iframe><p>Örnek kullanım;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/411eac6f0e6df896ba24db1ab593c79c/href">https://medium.com/media/411eac6f0e6df896ba24db1ab593c79c/href</a></iframe><p>Projenin kaynak kodlarına erişmek isterseniz;</p><p><a href="https://github.com/karabuluthakan/DotnetCoreMongoDb">karabuluthakan/DotnetCoreMongoDb</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8afa49e742dd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devopsturkiye/asp-net-core-mongodb-generic-repository-8afa49e742dd">Asp.Net Core MongoDb Generic Repository</a> was originally published in <a href="https://medium.com/devopsturkiye">Devops &amp; AI Türkiye☁️ 🐧 🐳 ☸️</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Asp.Net Core Dockerize]]></title>
            <link>https://medium.com/devopsturkiye/asp-net-core-dockerize-4e40b50f137c?source=rss-e3ddd311faec------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e40b50f137c</guid>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Hakan Karabulut]]></dc:creator>
            <pubDate>Sun, 19 Apr 2020 20:44:37 GMT</pubDate>
            <atom:updated>2020-04-25T21:27:18.099Z</atom:updated>
            <content:encoded><![CDATA[<p>Merhaba, bu makalede bir dotnet core uygulamasını docker ile ayağa kaldırma sürecinden bahsedeceğim.</p><p>Docker ile ilgili daha fazla bilgilendirme isterseniz yazmış olduğum <a href="https://medium.com/@karabuluthakan/docker-temelleri-5d40ac3e0ca8"><strong>Docker Temelleri</strong></a><strong> </strong>makaleme göz atabilirsiniz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bDNRDYHq2hhc34iEU7qBUQ.png" /></figure><p>Öncelikli olarak bir dotnet projesi kurulumu yapmamız gerekiyor. Bunun için terminalden çalışma klasörü yaratarak işe başlıyorum.</p><p>➜ mkdir dotnet-core-dockerize</p><p>➜ cd dotnet-core-dockerize</p><p>➜ dotnet-core-dockerize dotnet new sln — name DotNetCoreDockerize</p><p>➜ dotnet-core-dockerize dotnet new webapi — name Api</p><p>➜ dotnet-core-dockerize dotnet sln add {your_awesome_path}/dotnet-core-dockerize/Api</p><p>➜ dotnet-core-dockerize cd Api</p><p>➜ touch Dockerfile</p><p>şimdi Dockerfile içerisini doldurabiliriz.</p><pre>FROM mcr.microsoft.com/dotnet/core/sdk:3.1<br>WORKDIR /app<br>COPY . .<br>RUN dotnet restore<br>RUN dotnet publish Api.csproj -c Release -o out<br>WORKDIR out<br>ENV ASPNETCORE_URLS=&quot;https://*:9000&quot;<br>ENTRYPOINT [&quot;dotnet&quot;,&quot;Api.dll&quot;]</pre><p>Şimdi Dockerfile içinde adım adım yazmış olduğumuz komutları inceleyelim;</p><p><strong>FROM</strong> : Resmi <a href="https://hub.docker.com/_/microsoft-dotnet-core-sdk/">dotnet docker image</a>’ını çekiyoruz.</p><p><strong>WORKDIR /app</strong> : Çekmiş olduğumuz image ile çalışma klasörü belirliyoruz.</p><p><strong>COPY . .</strong> : İçindeki ilk “.” Dockerfile’ın bulunduğu klasörün içindeki tüm klasör ve dosyaları temsil eder. İkinci “.” ise /app ile belirttiğimiz çalışma klasörümüzü ifade eder.</p><p><strong>RUN dotnet restore :</strong> Projeyi güncel hale getiriyoruz.</p><p><strong>RUN dotnet publish Api.csproj -c Release -o out</strong> : dotnet publish ile hangi projeyi publish edeceğimizi ifade ediyoruz, ProjenizinAdı.csporj ile proje adını belirtmek gerekiyor. -c Release ile hangi modda publish edeceğimizi bildiriyoruz. -o ile nereye publish edeceğimizi ifade ediyoruz. Burada dikkat edilmesi gereken kısım /out yazıldığında /app içinde bir klasör oluşturmaz. /app içinde klasörü oluşturmak için <strong>out</strong> yazmalıyız. Bu klasör içine publish edilmiş dosyalar atanır.</p><p><strong>WORKDIR /out</strong> : Artık çalışma klasörümüz publish edilmiş dosyaların klasörlerin bulunduğu out olduğunu belirtiyoruz.</p><p><strong>ENV ASPNETCORE_URLS</strong> : Container içerisinden projemize erişebilmek için kullanmamız gerekmektedir. Burada “https://*” * kullanmamızın sebebi container içinde hangi IP adresi ile çalıştığını bilmediğimiz içindir. Vermiş olduğumuz port numarası ile erişim sağlıyoruz. Kullanımda olmayan herhangi bir port numarası verebilirsiniz.</p><p><strong>ENTRYPOINT</strong> : Dotnet projemizin çalıştığı .dll uzantısına erişim içindir.</p><p>Dockerfile oluştururken bir ide üzerinden yapmadığımız için dotnet projemizde ufak bir işlem yapmamız gerekmektedir. Properties klasörü içindeki <strong>launchSettings.json </strong>içerisine aşağıdaki ayarları eklemeliyiz.</p><pre>&quot;Docker&quot;:{<br>  &quot;commandName&quot;: &quot;Docker&quot;,<br>  &quot;launchBrowser&quot;: true,<br>  &quot;launchUrl&quot;: &quot;{Scheme}://{ServiceHost}:{ServicePort}&quot;,<br>  &quot;publishAllPorts&quot;:true<br>}</pre><p>Docker ile önce image’larımızı oluşturalım. Bunun için önce projenin bulunduğu klasöre girmemiz lazım, sonrasında;</p><p>➜ docker build -t dotnetapp:v1 .</p><p>dotnetapp projeye verdiğimiz isim, v1 tag, Dockerfile projenin içinde olduğu için “.” ile yolunu belirtiyoruz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HzteCAJRD1GAqMHdnylzhg.png" /></figure><p>Docker image’ları terminale <strong>docker images </strong>yazdığımızda görüntüleyebiliriz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ScXRLMA_vxagO6gg879QRg.png" /></figure><p>Şimdi projemizi 5000 portundan ayağa kaldıralım.</p><p>➜ docker run -p 5000:9000 dotnetapp:v1 — name mycontainer1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*LmOhGM9W40IvFA-PFlC7ag.png" /></figure><p>Artık localhost:5000 portundan uygulamamıza erişim sağlayabiliriz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uGJOFOD3z7rzFpSbuGyrfA.png" /></figure><h4><strong>MultiStage</strong> Build</h4><p>MultiStage durumu tek bir base image yerine birden fazla base image kullanma durumudur.</p><p>Örneğimizde Sdk image kullanma nedenimiz Dockerfile içinde dotnet cli komutlarını kullanmak içindir. Sdk image kullanıldığı durumda Docker image boyutu daha fazla olacaktır. İmage boyutu ne kadar büyükse container ayağa kaldırma, taşıma vb işlemler daha maliyetli olacaktır. Bu yüzden Dockerfile içerisini aşağıdaki gibi düzenliyoruz;</p><pre>FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as build<br>WORKDIR /app<br>COPY *.csproj .<br>RUN dotnet restore<br>COPY . .<br>RUN dotnet publish Api.csproj -c Release -o out<br>FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 <br>WORKDIR /app<br>COPY --from=build /app/out .<br>ENV ASPNETCORE_URLS=&quot;https://*:9000&quot;<br>ENTRYPOINT [&quot;dotnet&quot;,&quot;Api.dll&quot;]</pre><p>➜ docker build -t dotnetapp:v2 .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dLUs93MVNdcgQv_xJj2eTg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_cYcN8sDETjdP7SOVwywRQ.png" /><figcaption>İmage boyutları arasındaki fark</figcaption></figure><h4>.dockerignore</h4><p>Docker imager oluşturulduğu esnada image içinde oluşturulmasını istemediğiniz klasör ya da dosyaları buraya ekleyebilirsiniz. Terminalden proje klasörüne geldikten sonra aşağıdaki kodu yazarak oluşturabilirsiniz.</p><p>➜ touch .dockerignore</p><pre>**/bin/<br>**/obj/<br>**/Dockerfile*<br>**/.dockerignore*</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e40b50f137c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devopsturkiye/asp-net-core-dockerize-4e40b50f137c">Asp.Net Core Dockerize</a> was originally published in <a href="https://medium.com/devopsturkiye">Devops &amp; AI Türkiye☁️ 🐧 🐳 ☸️</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>