<?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 Emre Erkoca on Medium]]></title>
        <description><![CDATA[Stories by Emre Erkoca on Medium]]></description>
        <link>https://medium.com/@emreerkoca?source=rss-cdc19ce508c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nl4NUf0g_R-5jxjBonFuMw@2x.jpeg</url>
            <title>Stories by Emre Erkoca on Medium</title>
            <link>https://medium.com/@emreerkoca?source=rss-cdc19ce508c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 06:55:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@emreerkoca/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[The Pursuit of Passion]]></title>
            <link>https://emreerkoca.medium.com/the-pursuit-of-passion-845768ea6e18?source=rss-cdc19ce508c------2</link>
            <guid isPermaLink="false">https://medium.com/p/845768ea6e18</guid>
            <dc:creator><![CDATA[Emre Erkoca]]></dc:creator>
            <pubDate>Thu, 27 Jul 2023 18:12:40 GMT</pubDate>
            <atom:updated>2023-07-27T18:12:40.538Z</atom:updated>
            <content:encoded><![CDATA[<p>Why do we live? What is the meaning of life? If you think you need to find the right answers to this kind of questions you probably haven’t found your passion yet. When you try something new you might feel it’s your passion. Most people don’t even try. I didn’t say to you. Maybe you try to change yourself every time. Most people finish their jobs and do nothing. They’re unhappy with their jobs but do nothing about this situation. If you feel happy in your job and your work-life balance is good it’s good for you. If you’re not happy in your current circumstances and you don’t want to leave your bed in the morning you should change something in your life. You can try to change your point of view about life too. Also, you can try to find your passion. When you find it you might feel like you’re alive.</p><p>By the way, you don’t have to find a passion. Maybe your family is wealthy and you don’t have to work. Be careful about your expenses and don’t forget to invest. Otherwise, you might lose control and be broke after an unlucky gambling day.</p><p>If you want to find your passion think about your life. How do you spend your time in a day? What makes you happy? What are your interests? Maybe music, maybe painting, maybe cinema, maybe writing, maybe design. You can try whenever you want. If you think you find your passion, don’t spend your whole time on your passion. It’s the real world and you have to earn money if your family is not wealthy. If you find a way to make money from your passion it’s great for you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=845768ea6e18" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CQRS Pattern Implementation]]></title>
            <link>https://emreerkoca.medium.com/cqrs-pattern-implementation-64fd88b96720?source=rss-cdc19ce508c------2</link>
            <guid isPermaLink="false">https://medium.com/p/64fd88b96720</guid>
            <category><![CDATA[dotnet-core-cqrs]]></category>
            <category><![CDATA[cqrs-pattern]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[cqrs]]></category>
            <dc:creator><![CDATA[Emre Erkoca]]></dc:creator>
            <pubDate>Sun, 12 Dec 2021 18:17:48 GMT</pubDate>
            <atom:updated>2021-12-13T11:21:28.266Z</atom:updated>
            <content:encoded><![CDATA[<p>We suppose you have a crypto stock market platform. You have a lot of customers and you store their all transactions. You use the same database table for reading and writing. This is a traditional method. But it might not good solution in this scenario. Because writing is a detailed operation and you don’t need small details when you read people’s current stock value. Okay, you can use the same table. Let’s guess what kind of problems will you see when you use the same database table. I can explain in one sentence. Your database table will have a lot of data and you’ll read data slowly. Okay, maybe you can wait a few seconds for getting the current value but customers don’t like this kind of thing. Don’t worry. You won’t lose your customers. You can separate the writing and reading model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aq7xk9GshSxdtY_A" /><figcaption>Photo by <a href="https://unsplash.com/@emtm17?utm_source=medium&amp;utm_medium=referral">Marissa&amp;Eric</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>CQRS ( Command and Query Responsibility Segregation) is a pattern that separates read and write operations for a database. You’ll read two different things in CQRS. Commands and Queries.</p><ul><li>Commands write a write model table in your database.</li><li>Queries read data from read model table in your database.</li></ul><p>You can review this diagram. If you don’t understand anything, don’t worry. We’ll explain it step by step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*-VjZASVNde5TQVvO3gRoTw.png" /><figcaption>CQRS</figcaption></figure><ol><li>A command writes to write data store. Consider an insert operation to a database table.</li><li>After changing write model table we must update your read model table for consistency. We can publish an event about data change and we can update read model in subscriber. If you don’t understand this event or subscriber you can research event-driven architecture. You can read this <a href="https://levelup.gitconnected.com/event-driven-architectures-in-software-design-757d92b85df5">article </a>too. Also, we’ll explain this briefly.</li></ol><p>An event is a message that carries information. When you need notify something you publish events.</p><p>Subscriber (consumer) is reading events. When you publish a message, the subscriber receives this message. You can do what do you want after reading event. You can review this diagram. After reviewing this diagram you might understand step 2 clearly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*26F6Hhz83GdgxP-LiZ1ZOw.png" /></figure><p>3. It’s getting data from read model database table.</p><p>We have a simple project for CQRS. You’ll learn some parts of the project. You can see the project <a href="https://github.com/emreerkoca/article-samples/tree/master/ArticleSamples/DotnetCoreCqrsMediatR">here</a>. You can open the project in a new tab. Of course, you’ll see the details about the project here but not every detail.</p><p>It’s a Dotnet Core application. It contains <a href="https://github.com/jbogard/MediatR">MediatR </a>library. MediatR library is implementing <strong>mediator pattern</strong>. We’ll explain the project briefly.</p><p>There is no real database connection in the project. You won’t need to install a new database for running the project. We have a fake data store and fake data. You can review the code block below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1a0f05a8b8155803cfe044e1d70ee74/href">https://medium.com/media/e1a0f05a8b8155803cfe044e1d70ee74/href</a></iframe><p><strong>Methods:</strong></p><p><strong>AddWallet(…)</strong>: It add a new WalletWriteModel to write model database table.</p><p><strong>GetWalletReadModels(…): It reads </strong>WalletReadModel from read model database table.</p><p><strong>SetPublishedEvent(…): </strong>When a new record adds to write database table a message publishes to notify consumers. In this sample message name is <strong>WalletChangedNotification.</strong> We’ll see this below. After publishing a new message this method marks WalletWriteModel as published. After this method, we can be sure about the message is published for a new write operation.</p><p><strong>UpdateWalletReadModel(…): </strong>There is <strong>WalletReadModelUpdaterNotificationHandler </strong>class in the project. This is a consumer. We’ll see this below. When the consumer receives a message it updates the read model database table via <strong>UpdateWalletReadModel(…)</strong> method.</p><p>We can review controller action methods now.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8586f5453702d2443c61a0c1131121ee/href">https://medium.com/media/8586f5453702d2443c61a0c1131121ee/href</a></iframe><p>Post method sends <strong>AddWalletCommand.</strong> After sending the command it publishes <strong>WalletChangedNotification </strong>and calls <strong>SetPublishedEvent(…)</strong> method. You can see the command here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b0fpzWyfvPnU2adhoWqkzQ.png" /></figure><p>There is a command handler (<strong>AddWalletHandler</strong>) in the project. It handles <strong>AddWalletCommand </strong>commands and calls <strong>AddWallet(…) </strong>method and it writes to the write model table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EYhJF4mqzkVu97NMuZOYjg.png" /></figure><p><strong>Get(…) </strong>action method sends <strong>GetWalletQuery. GetWalletHandler </strong>handles <strong>GetWalletQuery</strong>. It calls <strong>GetWalletReadModel(…)</strong> method and it returns read model table results. You can see this in the project repository.</p><p>You might think about how we update the read model table after changing the write model. Post action method published <strong>WalletChangedNotification</strong> (message, event)<strong> </strong>and <strong>WalletReadModelUpdaterNotificationHandler </strong>(consumer)<strong> </strong>handles message and it updates the read model table. You can see the consumer below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CLwwinclTkxoAvlmHgF58A.png" /></figure><p>It was a simple scenario. If you see any mistake in this article you can tell me. I hope it might be helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64fd88b96720" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ASP.NET Core Middleware]]></title>
            <link>https://emreerkoca.medium.com/asp-net-core-middleware-22b1a5c9c4eb?source=rss-cdc19ce508c------2</link>
            <guid isPermaLink="false">https://medium.com/p/22b1a5c9c4eb</guid>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[middleware]]></category>
            <category><![CDATA[request-logging]]></category>
            <category><![CDATA[dotnet-core-middleware]]></category>
            <category><![CDATA[respose-logging]]></category>
            <dc:creator><![CDATA[Emre Erkoca]]></dc:creator>
            <pubDate>Tue, 03 Aug 2021 20:35:32 GMT</pubDate>
            <atom:updated>2021-08-03T20:35:32.401Z</atom:updated>
            <content:encoded><![CDATA[<p>We suppose you want to change requests and responses. You want to add headers to requests, or you want to log your requests and responses. You can use custom middleware. Middleware is assembled into an app pipeline. You can handle requests and responses via middleware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WJ9UZH0v0rZI8adf" /><figcaption>Photo by <a href="https://unsplash.com/@igalness?utm_source=medium&amp;utm_medium=referral">Igal Ness</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>You can see how does middleware work in the app pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*AOFsvDlKHQ8gDwbHkNbvSQ.png" /><figcaption>Middleware Pipeline</figcaption></figure><ol><li>The request is sending to middleware.</li><li>Some operations you want to do. You can change the request here. For example, adding headers to the request.</li><li>The request is sending to another middleware.</li><li>More logic. So you can do something about the response. For example response logging.</li></ol><p>I created two custom middleware for request logging and response logging. You can see a middleware class below. It’s logging each request.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/add21a6f5cf397a3290182ec474a0f3a/href">https://medium.com/media/add21a6f5cf397a3290182ec474a0f3a/href</a></iframe><p>A middleware class must include a public constructor with a parameter of type <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.requestdelegate?view=aspnetcore-5.0">RequestDelegate </a>and a public method named Invoke or InvokeAsync method with <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.httpcontext"><strong>HttpContext </strong></a>parameter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de1b59fed4d615082c31ded9d49bd17a/href">https://medium.com/media/de1b59fed4d615082c31ded9d49bd17a/href</a></iframe><p>When you add middleware to Startup.cs Configure method you can use your middleware. It’ll work for each request.</p><blockquote><em>app.UseMiddleware&lt;MiddlewareForRequestLogging&gt;();</em></blockquote><blockquote><em>app.UseMiddleware&lt;MiddlewareForResponseLogging&gt;();</em></blockquote><p>I won’t explain how to log a request or a response. If you want to learn more about them you can check <a href="https://github.com/microsoft/Microsoft.IO.RecyclableMemoryStream">RecyclableMemoryStream</a> and <a href="https://docs.microsoft.com/en-us/dotnet/api/system.io.stream?view=net-5.0">Stream</a>.</p><p>You can also read Microsoft’s <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/write?view=aspnetcore-5.0">document </a>about custom middleware. If you see something wrong you can text me. I don’t want to share wrong information)</p><p>You can also read Microsoft’s <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/write?view=aspnetcore-5.0">document </a>about custom middleware. If you see something wrong you can text me. I don’t want to share wrong information)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22b1a5c9c4eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Outbox Pattern]]></title>
            <link>https://emreerkoca.medium.com/outbox-pattern-2cb77704f16c?source=rss-cdc19ce508c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cb77704f16c</guid>
            <category><![CDATA[outbox-pattern]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[transactional-outbox]]></category>
            <category><![CDATA[message-broker]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <dc:creator><![CDATA[Emre Erkoca]]></dc:creator>
            <pubDate>Tue, 13 Jul 2021 14:35:36 GMT</pubDate>
            <atom:updated>2021-07-13T14:35:36.730Z</atom:updated>
            <content:encoded><![CDATA[<p>When you use message brokers you might lose your messages. When you lost your messages customer operations don’t work properly. When they can’t their operations you might lose your customers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xFdyY-dmSV6MoKF5" /><figcaption>Photo by <a href="https://unsplash.com/@pawell?utm_source=medium&amp;utm_medium=referral">Pawel Chu</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If you don’t want to lose your messages store them in the database. You can check your message table regularly (hosted service, worker service, etc.) and publish them. After publishing you can mark the database record as published. It’s the usual way.</p><p><strong>Outbox Pattern Step by step:</strong></p><ol><li>Do something. (Create a new user, send a message, etc.)</li><li>Create an event</li><li>Store event to the database</li><li>Read database regularly and publish messages</li><li>After consuming mark messages as consumed</li></ol><p>You can review this diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lvV87iE_dtkgJ6yfLzXiPg.png" /><figcaption>Outbox Pattern</figcaption></figure><p>I don’t want to use it like this. I changed this a little bit. After saving messages to the database I publish messages. They’re consuming and updating as consumed. When message publisher service is working it’s reading unconsumed messages. It’s publishing them and updating them as consumed.</p><p>You can review the customized outbox pattern diagram here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m_RimsNpuQXHJPFRbFBW8g.png" /></figure><p>I wanted to write code basically.</p><p>The message model is here:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a8aa4d837632c09007121aa7d1c40e0/href">https://medium.com/media/6a8aa4d837632c09007121aa7d1c40e0/href</a></iframe><p>You can see saving and publishing events steps in this code block:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/163fce23e18a325758c1cf6d798c723e/href">https://medium.com/media/163fce23e18a325758c1cf6d798c723e/href</a></iframe><p>When a published event is consuming, it’s updating as consumed. You can see it here:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5849b191eeeb77ebf80fca94919a0976/href">https://medium.com/media/5849b191eeeb77ebf80fca94919a0976/href</a></iframe><p>PutMessageAsProcessed method is updating messages as consumed. It’s adding process time for the consumed message.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53a0bf7433f871114a4ae9eefa9f8ed2/href">https://medium.com/media/53a0bf7433f871114a4ae9eefa9f8ed2/href</a></iframe><p>Okay. It’s time to check unconsumed messages and publish them. I created a hosted service for this. It’s working regularly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/261a138b82c20d962bf38e1ec4ee3089/href">https://medium.com/media/261a138b82c20d962bf38e1ec4ee3089/href</a></iframe><p>PublishMissingMessages method runs once in ten minutes. The method is here:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ce1db99b33e18ee5717d6691f8efa81/href">https://medium.com/media/7ce1db99b33e18ee5717d6691f8efa81/href</a></iframe><blockquote>CreatedOn &lt; DateTime.UtcNow.AddHours(-1) &amp;&amp; !m.ProcessTime.HasValue</blockquote><p>This expression checks unconsumed messages in the last one hour. If it finds any message it publishes them again.</p><p>You can review the repository from this <a href="https://github.com/emreerkoca/dotnet-core-rabbitmq-sample">link</a>.</p><p>If you’re thinking it’s not a good solution, I would like to know this. You can text.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cb77704f16c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Windows Service Using .NET Core]]></title>
            <link>https://emreerkoca.medium.com/building-a-windows-service-using-net-core-fdc68901b12f?source=rss-cdc19ce508c------2</link>
            <guid isPermaLink="false">https://medium.com/p/fdc68901b12f</guid>
            <dc:creator><![CDATA[Emre Erkoca]]></dc:creator>
            <pubDate>Thu, 03 Jun 2021 14:51:11 GMT</pubDate>
            <atom:updated>2021-06-04T00:49:53.019Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a Windows Service Using .NET Core</h3><p>If you want to work on something regularly, Windows services might be a good solution. I have to repeat some phrases and I wanted to send them to my phone. I thought I can’t create a mobile application for this. Also, I don’t like mobile programming. I’m using the Slack application and I thought I can send them via Slack. I found an <a href="https://medium.com/streamwriter/sending-automatic-messages-to-slack-from-asp-net-core-with-hangfire-86b60d09b289">article </a>about Slack integration and I created my application. Publishing was a problem for me. I have no server I just have my personal computer. At that time, I thought I can use my application as a Windows Service. I wanted to explain basically how to create a Windows Service.</p><p>Firstly, create a new Worker Service .NET Core project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*osS5OrDoXMZ8lT3lozThIg.png" /></figure><p>Install packages below to your project.</p><ul><li>Microsoft.Extensions.Hosting</li><li><strong>Microsoft.Extensions.Hosting.WindowsServices</strong></li><li>Serilog.AspNetCore</li></ul><p>Change Program.cs CreateHostBuilder() method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a5476f7612327b8f17cd4554f8ef1b7/href">https://medium.com/media/2a5476f7612327b8f17cd4554f8ef1b7/href</a></iframe><p>We called <strong>UseSerilog()</strong> method for writing logs to file. We called <strong>UseWindowsService() </strong>method because we want to use worker service as Windows Service.</p><p>Open Worker.cs file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/530113ef989d9314d6930856bcf7e2b3/href">https://medium.com/media/530113ef989d9314d6930856bcf7e2b3/href</a></iframe><p>You can do anything here. Send a message, send an email, backup database, etc.</p><p>Create a txt file for logging. Open appsettings.json and add these configuration settings.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77b6ef7c4efbb69a2e8dae67801c0809/href">https://medium.com/media/77b6ef7c4efbb69a2e8dae67801c0809/href</a></iframe><p>Don’t forget to change the path correctly. Otherwise, you can’t see logs in your file.</p><h3>Publish Worker Service Project</h3><p>Open the console and go to your project’s directory.</p><p>Run this command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f1399293d84e1cc14fb2ca1def2359c/href">https://medium.com/media/9f1399293d84e1cc14fb2ca1def2359c/href</a></iframe><p>You’ll see bin\release\netcoreapp3.1\publish directory in your project. When you open publish folder, you can see your project’s exe file.</p><p>We’ll create a new Windows Service now. Open your console as an administrator and run create service command by your published project’s directory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdd97f331e8f0ed898d80781c218097d/href">https://medium.com/media/cdd97f331e8f0ed898d80781c218097d/href</a></iframe><p>You’ll see your Windows Service when you open services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*yviC1O6pJEAf7RC4nX0uxQ.png" /></figure><p>When you restart your computer, it’ll start automatically. Because we used start= auto when creating a Windows service. If you want you can start it manually for the first time. You’ll see logs in your log file.</p><p>If you don’t use your service you can delete it via this command:</p><blockquote>sc delete “your service name”</blockquote><p>Also, you can review <a href="https://github.com/emreerkoca/article-samples/tree/master/ArticleSamples/SampleWindowsService">this </a>repository.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fdc68901b12f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why We Use TransactionScope]]></title>
            <link>https://emreerkoca.medium.com/why-we-use-transactionscope-7e8b50453ba0?source=rss-cdc19ce508c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e8b50453ba0</guid>
            <category><![CDATA[transactional]]></category>
            <category><![CDATA[transactionscope]]></category>
            <category><![CDATA[dotnet]]></category>
            <dc:creator><![CDATA[Emre Erkoca]]></dc:creator>
            <pubDate>Fri, 23 Apr 2021 12:10:02 GMT</pubDate>
            <atom:updated>2021-08-04T14:49:35.255Z</atom:updated>
            <content:encoded><![CDATA[<h3>TransactionScope Usage</h3><p>We suppose you have customers and your customers can share some posts in your system. When a user clicks to the “Delete My Account” button you should delete her/his posts and after delete account information.</p><p>When deleting post-operation processing it might get an error. Then it should roll back the operation. Because it might get an error (e.g: Posts couldn’t found) when it’s processing again. Also, when you want to do two operations (delete posts and delete account information) in the same block if you get an error while processing the second operation it should rollback. You can ensure this with TransactionScope.</p><p>I created a sample of this. It has two database operations. Firstly you can read the code block. After I’ll explain.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8203a56efab7d069e3219e1fd8c6a003/href">https://medium.com/media/8203a56efab7d069e3219e1fd8c6a003/href</a></iframe><p>I used AdventureWorks2012 database and I made two database operations. updatePersonPhoneSqlCommand updates person’s phone. updatePersonSqlCommand updates person after phone update. When it gets an error after the first operation it rolls back all operations.</p><h3>Example scenarios:</h3><ul><li><strong>Without any error:</strong></li></ul><p><strong>Before:</strong></p><p>PersonPhone =&gt; PhoneNumber: 697–555–0141</p><p>Person =&gt; ModifiedDate: 2021–01–01 00:12</p><p><strong>After running transactional code block:</strong></p><p>PersonPhone =&gt; PhoneNumber: 697–555–0145</p><p>Person =&gt; ModifiedDate: 2021–04–23 05:13</p><ul><li><strong>After getting an error while transactional code block running</strong></li></ul><p>Uncomment this line: //throw new TransactionAbortedException(“error”);</p><p><strong>Before:</strong></p><p>PersonPhone =&gt; PhoneNumber: 697–555–0141</p><p>Person =&gt; ModifiedDate: 2021–01–01 00:12</p><p><strong>After running transactional code block:</strong></p><p>PersonPhone =&gt; PhoneNumber: 697–555–0141</p><p>Person =&gt; ModifiedDate: 2021–01–01 00:12</p><p>There is no change. You can read more from the links below.</p><p>TransactionalScope class document is <a href="https://docs.microsoft.com/en-us/dotnet/api/system.transactions.transactionscope?view=net-5.0">here</a>.</p><p>Implementing an Implicit Transaction using Transaction Scope document is <a href="https://docs.microsoft.com/en-us/dotnet/framework/data/transactions/implementing-an-implicit-transaction-using-transaction-scope">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e8b50453ba0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Retry Policies]]></title>
            <link>https://emreerkoca.medium.com/retry-policies-99feec976a09?source=rss-cdc19ce508c------2</link>
            <guid isPermaLink="false">https://medium.com/p/99feec976a09</guid>
            <category><![CDATA[rabbitmq]]></category>
            <category><![CDATA[retry-policy]]></category>
            <category><![CDATA[mass-transit]]></category>
            <category><![CDATA[message-broker]]></category>
            <dc:creator><![CDATA[Emre Erkoca]]></dc:creator>
            <pubDate>Wed, 14 Apr 2021 22:50:21 GMT</pubDate>
            <atom:updated>2021-04-14T22:50:21.026Z</atom:updated>
            <content:encoded><![CDATA[<p>If you use message brokers (Kafka, RabbitMQ, etc.) you might have error queues. When your system being insufficient you might get transient errors and you get errors in your queue. Then you have to move them manually. If you’re getting a lot of transient errors your night might be a nightmare.</p><p>When a customer doing some operation she/he can’t wait until morning. If you want to solve this kind of error completely, you can make better your system (cloud solutions, etc.) If you can’t change your system, you can try different solutions. You can try to retry policies. I wrote this example for MassTransit and RabbitMQ but I think this solution might be possible for different message brokers too. You can search.</p><p>If you have no idea about message brokers, you can read <a href="https://medium.com/nerd-for-tech/dotnet-core-and-rabbitmq-df5e7038e5c5">this </a>article.</p><p>Retry policy checks your consumer before sending a message to the error queue. We suppose you have no retry policy. When you get an error in your consumer your message sends to the error queue.</p><h4>Retry Policies for MassTransit</h4><ul><li><strong>None:</strong> No retry</li><li><strong>Immediate:</strong> Retry immediately, up to the retry limit</li><li><strong>Interval: </strong>Retry after a fixed delay, up to the retry limit. It has two parameters. RetyCount is the number of retry attempts. Interval parameter can be an int value or TimeSpan.</li><li><strong>Intervals:</strong> Retry after a delay, for each interval specified. You can specify the Interval rule with this.</li></ul><p>I made an example of this. I’m trying to consume messages at different times. I wrote a method for generating different TimeSpan values. It’s generating different values. It’s consuming messages at different times because I thought I can reduce the message density.</p><p>It’s a simple solution. It’ll reduce your error queue count but when you increase retry count or intervals, the processing time of queues might be longer. You can read all configuration settings from <a href="https://github.com/emreerkoca/dotnet-core-rabbitmq-sample/blob/master/DotnetCoreRabbitMqSample.Api/DotnetCoreRabbitMqSample.Api/Startup.cs">here</a>. Also, you can review the repository.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/299a659fb75bea76a8298fdd898d5f69/href">https://medium.com/media/299a659fb75bea76a8298fdd898d5f69/href</a></iframe><p>This method is generating different timespan values.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/41f61fd0c833397ecb8c379d55f3058e/href">https://medium.com/media/41f61fd0c833397ecb8c379d55f3058e/href</a></iframe><p>This method is so simple. It just makes unique values.</p><p>Configuration on Startup file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b10eba8f6a9f15104367da1acb59dad3/href">https://medium.com/media/b10eba8f6a9f15104367da1acb59dad3/href</a></iframe><p>I added an Exception to MembershipStartedEventConsumer.cs. I suppose you already see the <a href="https://github.com/emreerkoca/dotnet-core-rabbitmq-sample">repository</a>. I think you know when a post request sends to MembershipController post method, it’ll publish an event and the consumer is trying to consume the message.</p><p>You can see consume times here:</p><p>t0: DateTime: 4/12/2021 10:12:58 PM</p><p>t1: DateTime: 4/12/2021 10:13:04 PM</p><p>t2: DateTime: 4/12/2021 10:13:08 PM</p><p>t3: DateTime: 4/12/2021 10:13:15 PM</p><p>The message will move to the error queue when it can’t consume. But when you get any transient error it might consume in second or third retry.</p><p>Also, you can review this diagram to understand the difference between using a retry policy or not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*WHkMM-1pzt7xYHUnwSmb4A.png" /></figure><p>I hope it might be helpful)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99feec976a09" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dotnet Core and RabbitMQ]]></title>
            <link>https://emreerkoca.medium.com/dotnet-core-and-rabbitmq-df5e7038e5c5?source=rss-cdc19ce508c------2</link>
            <guid isPermaLink="false">https://medium.com/p/df5e7038e5c5</guid>
            <category><![CDATA[mass-transit]]></category>
            <category><![CDATA[message-broker]]></category>
            <category><![CDATA[rabbitmq]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <dc:creator><![CDATA[Emre Erkoca]]></dc:creator>
            <pubDate>Sat, 20 Mar 2021 22:26:22 GMT</pubDate>
            <atom:updated>2021-03-29T02:21:17.155Z</atom:updated>
            <content:encoded><![CDATA[<p>RabbitMQ is an open-source message broker. When it’s explained with words it might be confusing. I’ll try to explain via a diagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*2HEhE_3579ZNLL46F6llBA.png" /></figure><p><strong>Producer:</strong> Producer publishes messages about events. The producer is an app in this diagram. When the user posts a new article system creates an article and publishes a message (ArticleCreatedEvent).</p><p><strong>Consumer: </strong>Consumers are listening to messages. When a message publishes, consumers trigger and read the message context. When the ArticleCreatedEvent message publishes, NotificationSenderConsumer and ArticlePriceCalculatorConsumer trigger in this diagram. NotificationSenderConsumer runs SendNotificationCommand and it sends notifications to followers of the author.</p><p>ArticlePriceCalculatorConsumer runs CalculateArticlePriceCommand and it calculates the price of the article.</p><p>I made a sample project to explain this subject. <a href="https://github.com/emreerkoca/dotnet-core-rabbitmq-sample">https://github.com/emreerkoca/dotnet-core-rabbitmq-sample</a></p><p>If you want to write a sample code about RabbitMQ, you can download and install RabbitMQ.</p><p><a href="https://www.rabbitmq.com/">https://www.rabbitmq.com/</a></p><p>I used MassTransit in this project. MassTransit open-source distributed application framework for .NET.</p><p><a href="https://masstransit-project.com/">https://masstransit-project.com/</a></p><p>I’ll explain the project step by step. I suppose you installed RabbitMQ.</p><p><strong>Create a Dotnet Core Web Application (Web API)</strong></p><p>Add MassTransit package to your project:</p><p>Command: dotnet add package MassTransit</p><p>If you don’t work with commands you can install the package from Nuget Package Manager.</p><p>Create MembershipStartedEvent class. It’s an event. It’ll keep your information to publishing.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2618fba071dc7b1bfb33567abaf6bc28/href">https://medium.com/media/2618fba071dc7b1bfb33567abaf6bc28/href</a></iframe><p>Create IMembershipService interface:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b072c26b80871bad2af4dbb6f67ea5d/href">https://medium.com/media/7b072c26b80871bad2af4dbb6f67ea5d/href</a></iframe><p>Create MemberShipService class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a374278ef9c3b355d4890fd63d5a993/href">https://medium.com/media/5a374278ef9c3b355d4890fd63d5a993/href</a></iframe><p>PostMembership method just publishes event. We suppose it already saved the user’s data. You can publish a new event like this.</p><p>When an event publishes, it process through a queue. A consumer consumes your message and it works your commands. When it got an error while working your message will be sent to an error queue. When you have messages on error queues you can move and process them.</p><p>You can open your local RabbitMQ panel from this URL: <a href="http://localhost:15672/">http://localhost:15672/</a></p><p>A queue:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*4bIjy1zx47E7_YTouVCRoQ.png" /></figure><p><strong>Ready:</strong> Queued message count for waiting to process.</p><p><strong>Unacked:</strong> Count of processed messages but it’s not clear. So, the consumer is saying “Yes, I’ll consume them” but there is no information about the process. When you see decreasing total message count you can understand they’re consuming.</p><p>An error queue:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*Xpi14DHmL1UA4n4aJEexRg.png" /></figure><p>Now add a new Controller (MembershipController.cs)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c87e9d03ab5b9dc8c5ad2eba47da5e34/href">https://medium.com/media/c87e9d03ab5b9dc8c5ad2eba47da5e34/href</a></iframe><p>If you confused about IMemberService you can search “dependency injection” and “dependency injection constructor injection”</p><p>I created a service class and I used it. There is no business or data access layer because it’s not a software architecture tutorial.</p><p>PostMembershipRequest method sends postMembershipRequest object to PostMembership method.</p><p>It’s not necessary to explain each part. You can check the repository for request classes, model classes, or response classes.</p><p>The consumer class looks like this. When the message published it comes to here:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a7d480f6f3c4e1d5a3a5046cbc77df0/href">https://medium.com/media/7a7d480f6f3c4e1d5a3a5046cbc77df0/href</a></iframe><p><strong>MassTransit Configuration</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1431aa8d4e92864692b15cb942bc8328/href">https://medium.com/media/1431aa8d4e92864692b15cb942bc8328/href</a></iframe><p>It’s adding consumers and defining queue names.</p><p>If you created other parts or downloaded the repository, it’s ready to run.</p><p>Put the breakpoint on Consume method and send post requests. You’ll see your messages will come to Consumer.</p><p>Post membership operations diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*jzpTf7AZ_ftRkUUDOjd5ww.png" /></figure><p>I can make mistakes. Because I’m not a machine. If you see any mistake in this article you can tell me. I hope it might be helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df5e7038e5c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dotnet Core Localization]]></title>
            <link>https://emreerkoca.medium.com/dotnet-core-localization-96c88e842219?source=rss-cdc19ce508c------2</link>
            <guid isPermaLink="false">https://medium.com/p/96c88e842219</guid>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[globalization]]></category>
            <category><![CDATA[localization]]></category>
            <category><![CDATA[csharp]]></category>
            <dc:creator><![CDATA[Emre Erkoca]]></dc:creator>
            <pubDate>Sat, 20 Feb 2021 19:49:31 GMT</pubDate>
            <atom:updated>2021-03-29T02:21:01.598Z</atom:updated>
            <content:encoded><![CDATA[<p>I had to make a multi-language application. Because there are a lot of languages and you might want to be global for more customers. I wanted to write a simple example before localization. I read documents and I felt a little bit confused. Then, I wanted to share my sample code.</p><p>You can store your text messages in a resource file. A resource record is composed of two parts. Name and value. Actually, there is one more part (comment) but probably you won’t use this part.</p><p>An example resource file looking like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/0*8WT8TSLh55_iFyWa" /></figure><p>You can create resource files for different languages.</p><p>Resource.resx, Resource.de.resx, Resource.es.resx, etc.</p><p>If you want to apply localization properly, names must be same in your resource files. When the localizer doesn’t find resource content, it returns null. I’ll explain this project step by step. <a href="https://github.com/emreerkoca/LocalizationExample">https://github.com/emreerkoca/LocalizationExample</a></p><p>It’s a simple Dotnet Core Web API project.</p><ol><li>Add Resources folder to your project.</li><li>Add your resource files.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/0*D7YTZvJ8S3i82xJX" /></figure><p>3. Add a new folder to your project as “Localize” and add a public class to Localize folder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c40a5d7551312244838489aaecf49f2e/href">https://medium.com/media/c40a5d7551312244838489aaecf49f2e/href</a></iframe><p>If you want you can use different names but your resource names and your resources must be suitable. You will reach resource content through this empty class.</p><p>Resource name: <strong>Localize</strong>.Resource.de.resx</p><p>The namespace of your class is LocalizationExample.<strong>Localize </strong>and the class name is Resource.</p><p>4. Startup Configuration</p><p>Add this code block to into ConfigureServices(IServiceCollection services) method in Startup.cs file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb71fd70ac4c2a731cfefb577ac6e6c7/href">https://medium.com/media/cb71fd70ac4c2a731cfefb577ac6e6c7/href</a></iframe><p>It’s adding supported languages for localizers. Showing your resource files and setting the default language.</p><p>Add this code block to <strong>Configure(IApplicationBuilder app, IWebHostEnvironment env)</strong> method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de29218b8538397317455a7a574aaf15/href">https://medium.com/media/de29218b8538397317455a7a574aaf15/href</a></iframe><p>It’s for automatically setting culture info for your localizer. You can set culture info by any request header value.</p><p>5. Showing Localized Messages</p><p>I used <strong>IStringLocalizer </strong>interface for reaching resource files. You can see an example usage here. Add dependencies and call the resource field name.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c554276f26183768ef1639a45eb87be6/href">https://medium.com/media/c554276f26183768ef1639a45eb87be6/href</a></iframe><p>Get() method will return “Hello!” because English is the default culture and English resource value is “Hello!” When you add “culture=de” to your request URL, you’ll change the culture as “de” and you’ll see “Hallo!” message.</p><p>If you want you can detect the current language from the “Accept-Language” header. You can change your configuration.</p><p>Change your ConfigureServices configuration part like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a0a83bbfbc8268a5845ebe4dee0f386/href">https://medium.com/media/7a0a83bbfbc8268a5845ebe4dee0f386/href</a></iframe><p>It’s reading the “Accept-Language” header value and getting the default language. Put a breakpoint after the language variable and see values. It’s changeable for different browser languages. If you feel confused when you read CustomRequestCultureProvider, ProviderCultureResult, etc. you can read them from official Microsoft documents.</p><p>Now, you don’t have to add a culture parameter to request URL. You can try to get values from English and German browsers.</p><p>You can read this document for detailed information.</p><p><a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-5.0">https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-5.0</a></p><p>I have nothing to say after this. I hope it might be helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96c88e842219" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MutationObserver and Event Usage]]></title>
            <link>https://emreerkoca.medium.com/mutationobserver-and-event-usage-c620c0074ed4?source=rss-cdc19ce508c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c620c0074ed4</guid>
            <category><![CDATA[events]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[webapi]]></category>
            <category><![CDATA[mutationobserver]]></category>
            <dc:creator><![CDATA[Emre Erkoca]]></dc:creator>
            <pubDate>Fri, 29 May 2020 22:05:32 GMT</pubDate>
            <atom:updated>2020-05-29T22:05:32.199Z</atom:updated>
            <content:encoded><![CDATA[<p>I want to explain it through an example. Say you have your own company and you’re working with e-commerce companies. Your customer says to you “Can you provide user’s last added product for another consultant company. We need this information” and you said “Yes, we can do this”</p><p>Of course, you can find a professional solution to this problem. I’ll make this with MutationObserver and Event. MutationObserver is using detect DOM changes. For example, you have an element. You can detect any changes in this element. Adding a new child element, changing element content, adding a new attribute, etc. I used it for my card page element. It’s imitating a basic cart page. I’ll add a child div to here as a product.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b192e5411238d745c863c03d22996829/href">https://medium.com/media/b192e5411238d745c863c03d22996829/href</a></iframe><p>I added a new child element in this code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ac66edd5c2c3aa85c4f036892892e90/href">https://medium.com/media/9ac66edd5c2c3aa85c4f036892892e90/href</a></iframe><p>I used setTimeout to wait for 4000 milliseconds. Because we want to detect DOM changes. It’ll trigger after 4000 milliseconds. You can review MutationObserver sample codes from here:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f7951f8974e56739db6e75f97242543/href">https://medium.com/media/7f7951f8974e56739db6e75f97242543/href</a></iframe><p>I wrote createAndTriggerEvent function for creating a new Event and triggering it. When our data is ready we’re triggering it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86bcae350a3ab0c1cb92c7ba955ce31b/href">https://medium.com/media/86bcae350a3ab0c1cb92c7ba955ce31b/href</a></iframe><p>Finally, I’m listening to our custom event. When it’s triggering we’re catching data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc4fc14c8040df9171d34a47c68fdf31/href">https://medium.com/media/bc4fc14c8040df9171d34a47c68fdf31/href</a></iframe><p>You can get all JavaScript codes from here:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06bfbb38382de22c3a8e8bdfddce96c6/href">https://medium.com/media/06bfbb38382de22c3a8e8bdfddce96c6/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c620c0074ed4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>