<?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 Amina Mim on Medium]]></title>
        <description><![CDATA[Stories by Amina Mim on Medium]]></description>
        <link>https://medium.com/@mim.aminakhatun?source=rss-6c6078afdeb2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ofmQLxJaq29LXjmBznVBfg.png</url>
            <title>Stories by Amina Mim on Medium</title>
            <link>https://medium.com/@mim.aminakhatun?source=rss-6c6078afdeb2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 20:28:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mim.aminakhatun/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 End of a Beautiful Life”]]></title>
            <link>https://medium.com/pen-with-paper/the-end-of-a-beautiful-life-efd514f8fc58?source=rss-6c6078afdeb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/efd514f8fc58</guid>
            <category><![CDATA[art]]></category>
            <category><![CDATA[pen-with-paper]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[self-reflection]]></category>
            <category><![CDATA[self-awareness]]></category>
            <dc:creator><![CDATA[Amina Mim]]></dc:creator>
            <pubDate>Wed, 01 Jul 2026 22:26:46 GMT</pubDate>
            <atom:updated>2026-07-01T22:26:46.078Z</atom:updated>
            <content:encoded><![CDATA[<h4>Some days begin with no intention of becoming memorable. This was supposed to be one of those days.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fSpbhtsaH0QCG5IrqupdMA.jpeg" /><figcaption><em>Persistence</em>, Bhumi Art Gallery, Bangladesh — June 2026.</figcaption></figure><p>After a particularly heavy week of work and responsibilities, all I wanted was a light day with friends. We had planned to visit a newly opened bookstore we had been excited about for weeks, try some food we’d been hearing about, wander around a little, and then head home before evening. Nothing extraordinary. Just a small pause before life resumed.</p><p>Before reaching the bookstore, we passed a few paintings displayed outside. I barely slowed down at first. I assumed they were simply decorative pieces. Then one painting subtly pulled me back.</p><p>Its title read: <em>“The End of a Beautiful Life.”</em></p><p>At first, I didn’t understand it. But as I kept staring, the flower slowly came into view. A dying flower, almost withered. Suddenly, the title and the painting became one. It was no longer just a flower, it was something that had once been beautiful, now carrying the dignity of its ending. I don’t know why that painting stopped me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ggiAf-iwrropSkzcwNu9aQ.jpeg" /><figcaption><em>Persistence</em>, Bhumi Art Gallery, Bangladesh — June 2026.</figcaption></figure><p>Maybe because beauty and grief have never felt like opposites to me.</p><p>Maybe because I’ve known what it means to hold both at once.</p><p>My friends, laughing and taking photos, faded in the background. I was just standing mesmerized in front of oil paint, but somehow it felt as though I was standing inside the painter’s thoughts.</p><p>I wanted to stay longer. But I couldn’t. The bookstore was what we had come for.</p><p>The store was amazing. Shelves full of books I wanted to take home. Quiet corners. That familiar feeling of wanting to read everything at once. A little bit of disappointment at the price tags. Laughter with my friends. The aroma of new food. Arguments over little things the way good friends do. For a while, the dying flower disappeared from my mind.</p><p>But just before leaving, another painting caught my eye.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mrdLIoNS1RJAS1m7YCuJJA.jpeg" /><figcaption><em>Persistence</em>, Bhumi Art Gallery, Bangladesh — June 2026.</figcaption></figure><p>A rose this time, bright pink, full of life.</p><p>As I walked closer, I noticed something I had completely missed earlier. These weren’t just paintings on display. They belonged to an exhibition called <em>“Persistence”</em>, hosted at <em>Bhumi Art Gallery</em>, Bangladesh. Inside, I wandered from painting to painting. Some were vibrant, some subtly aesthetic. The painting of the pigeons surprised me, the oil painting of grass held me there, the painting of the lilies made me want to submerge, the horizon painting left an ache, all while having a quiet voice at the back of my mind saying, it’s time to leave, I had a train to catch, evening was approaching.</p><p>Yet another voice kept whispering, “Just one more.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v3HdPnUFGJceEA79UTdgyg.jpeg" /><figcaption><em>Persistence</em>, Bhumi Art Gallery, Bangladesh — June 2026.</figcaption></figure><p>I wasn’t looking at paintings anymore. I was looking into the minds of the people who had created them. Each brushstroke felt like a conversation with someone I had never met. At that moment, another realization surfaced. For the first time in a very long time, I felt like…just myself. I remembered a little girl sitting on the grass in the winter sun with a book in her hands, so completely absorbed in its pages that she only looked up when her mother called her inside for snacks.</p><p>She loved getting lost in things.</p><p>Books. Ideas. Small details. Simple beauty.</p><p>Somewhere along the way, life had become louder than wonder.</p><p>Standing in that gallery, I could see the reflection of that little girl, now a woman, all grown up and wiser, but still with the same habit of getting lost in things, still holding the same heart.</p><p>Eventually, we had to leave. I hadn’t seen every painting properly. There wasn’t time. Oddly enough, that incompleteness felt appropriate too. The very first painting had been called <em>“The End of a Beautiful Life”</em>. Maybe beautiful things are like that, they leave us wishing for just a little more. Maybe that’s true of exhibitions. Maybe that’s true of conversations.</p><p>Maybe that’s true of life itself. Life ends mid sentence, mid breath.</p><p>We say goodbye before we’ve said everything. We carry unfinished moments with us, hoping they’ll continue living somewhere inside.</p><p>On the train home, I kept thinking about the artists. If I could thank them, I wouldn’t tell them how beautiful their paintings were. I’d thank them for creating something capable of touching another person’s heart.</p><p>Not happiness.</p><p>Not dopamine.</p><p>Wonder.</p><p>And perhaps wonder was never something I had lost. Perhaps it had simply been waiting, patiently, for me to notice it again in the form of colors and strokes on a withered flower.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9C4IcnTQjWZP1tvlHMdb3A.jpeg" /><figcaption><em>Persistence</em>, Bhumi Art Gallery, Bangladesh — June 2026.</figcaption></figure><p>A few days later, I learned that the exhibition had officially ended a few days earlier. For reasons I still don’t know, it had remained open till the day I visited.</p><p>Some encounters simply arrive when we’re ready for them.</p><p><strong>We are finally on social media.. Come say hi…</strong></p><p><strong><em>Subscribe </em></strong><em>and </em><strong><em>follow </em></strong><em>our official social handles on </em><a href="https://www.instagram.com/penwithpaperpub"><strong><em>Instagram </em></strong></a><strong><em>| </em></strong><a href="https://x.com/penwithpaperpub"><strong><em>X </em></strong></a><strong><em>| </em></strong><a href="https://www.facebook.com/profile.php?id=61584630580257#"><strong><em>Facebook</em></strong></a><em>.</em></p><p><em>Feel free to </em><strong><em>mention</em></strong><em> / </em><strong><em>tag</em></strong><em> us on these </em><strong><em>social</em></strong><em> platforms whenever you want to </em><strong><em>promote</em></strong><em> or </em><strong><em>collaborate</em></strong><em> on your content. We love watching </em><strong><em>you</em></strong><em> </em><strong><em>grow</em></strong><em> with this </em><strong><em>community.</em></strong></p><p><em>This story published on “</em><a href="https://medium.com/pen-with-paper"><strong><em>Pen With Paper</em></strong></a><strong><em>”</em></strong><em> — a fresh space where writers bring their thoughts, stories, and ideas to life. </em><strong><em>Want to share your voice? </em></strong><em>Join our community, and together, “</em><strong><em>We Elevate Your Stories”</em></strong></p><p><a href="https://medium.com/pen-with-paper/pen-with-paper-submission-guidelines-2026-a-brand-new-way-to-be-added-as-a-writer-e9a7682c8fca">Pen With Paper Submission Guidelines 2026 : A Brand New Way to Be Added as a Writer</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efd514f8fc58" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pen-with-paper/the-end-of-a-beautiful-life-efd514f8fc58">“The End of a Beautiful Life”</a> was originally published in <a href="https://medium.com/pen-with-paper">Pen With Paper</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Prestige of EF Core: When One Entity Became Two]]></title>
            <link>https://medium.com/@mim.aminakhatun/the-prestige-of-ef-core-when-one-entity-became-two-9bedc8a6d1de?source=rss-6c6078afdeb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/9bedc8a6d1de</guid>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[debugging]]></category>
            <dc:creator><![CDATA[Amina Mim]]></dc:creator>
            <pubDate>Sat, 02 May 2026 17:28:11 GMT</pubDate>
            <atom:updated>2026-05-02T17:34:14.026Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3slOzWIagN4b5WL48XiIMg.jpeg" /><figcaption>The Prestige (2006)</figcaption></figure><p><a href="https://en.wikipedia.org/wiki/The_Prestige"><em>The Prestige</em></a> is built on a dangerous idea: what happens when one identity becomes two? In the film, the illusion isn’t the trick — it’s the duplication, one man, two identities.</p><p>EF Core, as it turns out, doesn’t like that kind of illusion.</p><p>A while ago, I ran into a similar problem, although my “duplicates” weren’t people — they were EF Core entities.</p><p>At first, everything seemed perfectly fine.</p><p>The cancellation flow was routine — update a few logs, clean things up, move on. No red flags, no edge cases, nothing that hinted at trouble. And for a while, it behaved exactly as expected.</p><p>Until it didn’t.</p><p>Out of nowhere, EF Core threw an exception that felt… out of place:</p><pre>The instance of entity type &#39;X&#39; cannot be tracked because another instance with the same key value is already being tracked.</pre><p>That was the first crack in the illusion. One version of the entity was invisible to the context, until another instance of the same entity appeared fully tracked. It was as if EF Core was saying, <em>“I already have this entity on stage — where did this second one come from?”</em></p><p>It reminded me of <a href="https://en.wikipedia.org/wiki/The_Prestige"><em>The Prestige</em> </a>— that moment when one man walks into the machine… and somehow, two come out. Identical. Indistinguishable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*4M-CPLnfCZ0ZCDxLNNVCRA.jpeg" /><figcaption>Albert and Frederick (The Prestige, 2006)</figcaption></figure><p>There weren’t supposed to be duplicates. The data was correct. The queries were straightforward. Nothing in the flow explicitly created or attached multiple instances of the same entity.</p><p>And yet, EF Core insisted otherwise.</p><p>Somewhere beneath the surface, two versions of the same entity existed at the same time — one visible, one hidden — both real, and both conflicting the moment they collided. The more I looked at it, the less it made sense. It no longer felt like a simple bug. So, I dropped everything else — the higher-level explanations, the mental shortcuts, the “this should work” reasoning — and went all the way down. Line by line. Query by query. Execution path by execution path.</p><p>That’s when the illusion began to take shape.</p><p>Early in the flow, the system had fetched the logs using AsNoTracking(). It was a deliberate choice—these entities were only needed for reading, and skipping tracking felt like a harmless optimization. Cleaner, lighter, faster. And on its own, it was. But deeper in the workflow, another method stepped in and unlike the earlier query, this one relied on EF Core’s default behavior. It loaded the same entities again, this time fully tracked through AsQueryable().</p><p>That was the moment the trick revealed itself.</p><p>The system hadn’t duplicated the data.<br>It had duplicated the instance.</p><p>Two separate instances, both representing the same identity, trying to exist inside a single DbContext. But unlike <em>The Prestige</em>, where two men—Albert and Frederick—can share one identity as <a href="https://www.imdb.com/title/tt0482571/characters/nm0000288/">Alfred Borden</a>, EF Core refuses to collapse identity across instances.</p><p>And that’s where the exception was born.</p><p>There was no dramatic flaw in EF Core. No hidden bug waiting to be discovered. Nothing broken in the framework itself. Just a simple rule, enforced without compromise: <em>a single identity cannot exist in two tracked states within the same </em><em>DbContext.</em> Small, reasonable, almost forgettable in isolation.</p><p>The fix, in hindsight, was almost trivial. But getting there required stepping away from assumptions and understanding what EF Core was actually doing beneath the abstraction — not just what I expected it to do.</p><p>And that’s the part that stayed with me.</p><p>Because problems like this aren’t really about EF Core, or tracking, or queries. They’re about decision-making. About understanding what cost is acceptable for optimization, and when that optimization quietly introduces complexity you didn’t plan for. Tools and AI agents can accelerate how we write code, but they don’t replace the need to understand the principles underneath it. At some point, you still have to reason about behavior, trade-offs, and system design yourself. Without that, something correct in isolation can easily become something wrong in motion.</p><p>Like any good trick, it only feels impossible until you see both sides of it at the same time.</p><p>After that, there’s nothing left to argue with.</p><p>Only understanding… and the quiet realization that it was never magic at all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wI2bwtveM66vVRDZ1-rhhQ.jpeg" /><figcaption>Alfred Borden (The Prestige, 2006)</figcaption></figure><p>Adios.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9bedc8a6d1de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When Growth Feels Like Debugging]]></title>
            <link>https://medium.com/@mim.aminakhatun/when-growth-feels-like-debugging-6a07b9e4b20f?source=rss-6c6078afdeb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a07b9e4b20f</guid>
            <category><![CDATA[self-awareness]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[self-reflection]]></category>
            <dc:creator><![CDATA[Amina Mim]]></dc:creator>
            <pubDate>Wed, 29 Oct 2025 18:31:51 GMT</pubDate>
            <atom:updated>2025-10-29T18:31:51.973Z</atom:updated>
            <content:encoded><![CDATA[<p><em>PS: Not much of a Tech post.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iYlvx0H_Nnwyn6jF" /><figcaption>Photo by <a href="https://unsplash.com/@emilep?utm_source=medium&amp;utm_medium=referral">Emile Perron</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>There’s something strangely personal about debugging.</p><p>You start by noticing that something isn’t working as expected — a result feels off, a pattern breaks, an exception says, <em>“something’s wrong here.” </em>or sometimes, the whole system crashes, leaving you staring at a blank screen and wondering where it all went wrong.</p><p>You don’t fix it right away. You trace it. Line by line. One step at a time.</p><p>You step through your own logic, your own set of code until you find where it drifted from what you intended. Sometimes it’s just some minor issue, like a typo or a missing semicolon, something you can fix instantly. And sometimes, it turns out to be a whole misunderstanding of how things were meant to interact.</p><p>Lately, I’ve realized I’ve been debugging myself, too.</p><p>My patterns. My inner system. My perception of the world. I’ve been tracing my own logic, trying to understand which part of me keeps failing silently in the background. And honestly, I’ve found quite a few things.</p><h4><em>The Misplaced Dependency</em></h4><p>Somewhere in my system, I linked too many variables to one external source — something I relied on too heavily, a faulty one at that. When their state changed unexpectedly, my entire structure wobbled. I’m learning to decouple now — learning to keep my stability as a separate module so that no single external source can disrupt my entire system.</p><h4>The Unhandled Exceptions</h4><p>Emotions I never got to process properly — grief, frustration, fear, anger — kept crashing silently in the background, waiting for a trigger. I’m learning to handle them better — to sit with them when they appear instead of forcing an instant fix.</p><h4>The Deprecated Logic</h4><p>Some of my old beliefs don’t belong in this version of me anymore. They were written for a different stage of life, under different conditions, some even by faulty logic. I’m rewriting them with new understanding, removing what no longer matters, adding what gives new perspective, building a better version of me.</p><h4>The High Resource Consumption</h4><p>Not overthinking, but overprocessing. Too many threads running at once: emotions, responsibilities, memories, hopes, fears, rage — all competing for the same core. I don’t crash, but my clarity fragments, so does my inner compass. I’m learning to close some processes, queue what can wait, and let the system idle once in a while.</p><p>I haven’t found all the answers yet, but maybe I will as I go forward — doing more self-debugging. Debugging isn’t glamorous, neither for a system nor for a mind. It’s repetitive, sometimes frustrating, but I realized that it is deeply human. Every red line in the inner console is just a message: “<em>something needs your attention here, something needs to change.</em>”</p><p>And once you’re done, your system becomes reliable again — ready to produce something meaningful, ready to become a better version.</p><p>Just as <a href="https://en.wikipedia.org/wiki/William_Wordsworth">Wordsworth </a>perceived,</p><blockquote><a href="https://www.poetryfoundation.org/poems/45550/she-was-a-phantom-of-delight">“And now I see with eye serene, The very pulse of the machine.”</a></blockquote><p>I’ve begun to sense the heartbeat of my own internal system. And perhaps that’s what growth really is —</p><p>Not flawless code, not perfection, not immediate fix, but seeing, with a serene eye, the very pulse of your own framework — steady, imperfect, and alive.</p><p><em>Sometimes, debugging isn’t about code. It’s about learning how to run better — within yourself.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a07b9e4b20f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“The Storm Wrapped in Wool”]]></title>
            <link>https://medium.com/@mim.aminakhatun/the-storm-wrapped-in-wool-43954130ec09?source=rss-6c6078afdeb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/43954130ec09</guid>
            <category><![CDATA[healing]]></category>
            <category><![CDATA[self-worth]]></category>
            <category><![CDATA[strength]]></category>
            <category><![CDATA[storytelling]]></category>
            <dc:creator><![CDATA[Amina Mim]]></dc:creator>
            <pubDate>Mon, 07 Apr 2025 16:39:29 GMT</pubDate>
            <atom:updated>2025-04-07T16:39:29.447Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kR1NDGVbjURVFNW5rXVuyA.png" /></figure><p>Once upon a time, in a quiet meadow at the edge of a dark forest, there lived a gentle sheep. She was not just soft in wool, but fierce in spirit. She wasn’t naïve, nor weak. She chose her path with care, stepped with wisdom, mended her own wounds and held the storms inside her steady. Many feared the woods, but she stood near its edge, unafraid, believing not everything in the shadows meant harm.</p><p>One day, a young wolf stepped out of the forest. He spoke gently, walked slowly, and wore no snarl on his face. He believed he was different. He told her he would stand guard, that he had left the pack behind, that the wild in him would bend to protect, not harm.</p><p>And though her kind warned her, though the winds whispered, “Wolves are wolves,” the sheep saw something in him — a softness she thought would be safe.</p><p>So she let him stay.</p><p>They made a little world between forest and field, a place neither belonged to fully, but both stayed in. The sheep gave him her trust, her dreams, her time. She showed him the stars. Taught him stillness. She believed the wild could be softened with enough love.</p><p>And the wolf — he was happy too. Genuinely. For a time, he believed he could change. He believed that the fire in his chest could warm, not burn. That perhaps he could unlearn the hunger, bury the instinct, shed the shadow of the pack. He looked at her and saw not prey, but peace. And he wanted that peace, more than he had words for.</p><p>But wolves — wolves have teeth. And when the forest called again, when his pack howled and reminded him who he was, the wolf changed.</p><p>Slowly, at first. A growl here. A coldness there. The pull of the wild growing louder than the quiet they had made. And then one day, he stepped back, baring fangs — not at the world, but at her.</p><p>And maybe he didn’t mean to. Maybe it wasn’t cruelty, but fear. The kind that makes even the gentlest hands strike when they’re trembling. Maybe, in some twisted way, it hurt him too — to bare teeth at the one who had only ever shown him kindness. But intentions don’t soften wounds.</p><p>The sheep didn’t run. She stood frozen, not because she was afraid, not because she was a sheep, but because she couldn’t believe how the wolf had become what he once swore to protect her from, how the healer became the one to open up her wounds and pour poison in her veins.</p><p>But then she turned. And she walked away — scarred, but with her head high. She didn’t cry out. She didn’t look back. Because she knew now: even kindness cannot make a wolf forget his hunger.</p><p>And the meadow grew quiet again. The sheep stood alone. But not broken. She had lost something, yes — but not herself.</p><p>Because she was never just a sheep.</p><p>She was the storm wrapped in wool. The one the wind watched in awe. And her kind, who once whispered warnings, now watched with quiet reverence. They saw not a mistake — but a lesson, a legacy. A testament to courage. She had walked into the shadow, faced the wild, and walked back out whole.</p><p>They called her wise now. Brave. Worthy.</p><p>And someday, not near the forest, but in a place where light kissed the earth gently, she’d find others like her — souls who carried softness and strength alike. Souls who would never wear teeth behind their smiles.</p><p>And the sheep? She walked on.</p><p>Free. Fierce. And finally, home.</p><blockquote>If this story resonates with you, I’m glad you found it.<br>The world is more beautiful because of the Storms Wrapped in Wool — like you.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43954130ec09" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Semaphores Can Keep the Chaos of Your Apps in Check]]></title>
            <link>https://medium.com/@mim.aminakhatun/how-semaphores-can-keep-the-chaos-of-your-apps-in-check-d62f384ec07c?source=rss-6c6078afdeb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d62f384ec07c</guid>
            <category><![CDATA[semaphore]]></category>
            <category><![CDATA[multithreading]]></category>
            <dc:creator><![CDATA[Amina Mim]]></dc:creator>
            <pubDate>Fri, 14 Mar 2025 17:32:28 GMT</pubDate>
            <atom:updated>2025-03-14T17:32:28.436Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Z2g55aCsBdc3pYO2" /><figcaption>Photo by <a href="https://unsplash.com/@mj_meone?utm_source=medium&amp;utm_medium=referral">Ma Joseph</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Working with multi-threaded applications can be a bit tricky, right? To make the most of your resources and avoid those nasty race conditions, you need to synchronize your threads properly. That’s where semaphores come in — a handy tool to help you manage access to limited resources. In this post, we’ll break down what semaphores are, how they work, and how you can use them in your .NET applications. Let’s dive in!</p><p>A semaphore is like a traffic light for your threads, keeping everything organized by allowing a set number of them to access a resource simultaneously. For example, imagine a trendy coffee shop with only five seats. When a customer walks in and there’s an available seat, they can sit down and enjoy their coffee, and the count of available seats decreases. When a customer leaves, the count goes back up, signaling that another customer can come in and grab a spot. If the shop is full, new arrivals have to wait in line. This simple analogy illustrates how semaphores ensure that only five customers — or threads in this case — can occupy the coffee shop at any given time. In .NET, you can use System.Threading.Semaphore or its leaner cousin, System.Threading.SemaphoreSlim, to implement this kind of control. The latter is designed specifically for managed code and is a bit faster.</p><p>Let’s look at a fun example. Imagine you’re building a simulation of a gaming arcade where players line up to use the only three VR stations available. Here’s how you can manage the players’ access using a semaphore:</p><pre>using System;<br>using System.Threading;<br>using System.Threading.Tasks;<br><br>class Program<br>{<br>    static SemaphoreSlim semaphore = new SemaphoreSlim(3); // Only 3 VR stations available<br><br>    static async Task PlayVRGameAsync(int playerNumber)<br>    {<br>        Console.WriteLine($&quot;Player {playerNumber} is waiting for a VR station...&quot;);<br>        await semaphore.WaitAsync();<br>        <br>        try<br>        {<br>            Console.WriteLine($&quot;Player {playerNumber} is playing on a VR station...&quot;);<br>            await Task.Delay(3000); // Simulate gameplay<br>            Console.WriteLine($&quot;Player {playerNumber} is done playing and leaving the station.&quot;);<br>        }<br>        finally<br>        {<br>            semaphore.Release();<br>            Console.WriteLine($&quot;Player {playerNumber} freed up a VR station.&quot;);<br>        }<br>    }<br><br>    static async Task Main(string[] args)<br>    {<br>        var tasks = new Task[10];<br><br>        for (int i = 0; i &lt; 10; i++)<br>        {<br>            int playerNumber = i + 1;<br>            tasks[i] = PlayVRGameAsync(playerNumber);<br>        }<br><br>        await Task.WhenAll(tasks);<br><br>        Console.WriteLine(&quot;All players have had their turn.&quot;);<br>    }<br>}</pre><p>In this example, the semaphore acts as a manager for the VR stations, allowing only three players to play at a time. As soon as one player finishes and releases their station, another player gets the chance to jump in. The SemaphoreSlim.WaitAsync method ensures that the players wait without blocking the system unnecessarily, which is especially useful for high-performance applications. And just like at the arcade, it’s important to make sure every player gets their fair turn by properly releasing the semaphore when they’re done.</p><p>Semaphores are incredibly useful when you’re working with limited resources like database connections, file handles, or network bandwidth. For example, if you’re processing items from a job queue or making API calls, throttling the number of concurrent tasks can prevent your system from becoming overloaded. By using a semaphore, you ensure that everything runs smoothly without overburdening your resources.</p><p>When working with semaphores, it’s important to <strong>use them correctly</strong>. Always ensure that the number of Release calls matches the number of Wait or WaitAsync calls. Over-releasing or under-releasing can disrupt the counter, causing unexpected behavior. Another good practice is to keep the code inside the semaphore-protected section as short as possible. This reduces contention and keeps things running efficiently.</p><p>Semaphores are a powerful way to manage shared resources and synchronize threads in multi-threaded applications. They’re straightforward to implement and incredibly effective in the right scenarios. With a bit of practice, you’ll find them indispensable for building robust, efficient .NET applications. Got a tricky synchronization problem? Try using a semaphore — it might just be the perfect solution.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d62f384ec07c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamic Data Binding and Reflection in C#: A Practical Example]]></title>
            <link>https://medium.com/@mim.aminakhatun/dynamic-data-binding-and-reflection-in-c-a-practical-example-44680afcf7a2?source=rss-6c6078afdeb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/44680afcf7a2</guid>
            <dc:creator><![CDATA[Amina Mim]]></dc:creator>
            <pubDate>Fri, 26 Jan 2024 18:45:30 GMT</pubDate>
            <atom:updated>2024-01-26T18:45:30.305Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1WzX3HMG6StpoQKU" /><figcaption>Photo by <a href="https://unsplash.com/@marcojodoin?utm_source=medium&amp;utm_medium=referral">Marc-Olivier Jodoin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Not too long ago, I encountered a scenario where I needed to make API calls to different services dynamically and bind a client-provided custom HTML string with the response data elements. In essence, I had to make an API call to a random service, receive an unknown (runtime) response, and manipulate an input string with the properties of that response. This is where the power of dynamic data binding and the use of Reflection to handle metadata at runtime became apparent to me.</p><p>Dynamic binding is essential while working with generic data structures or responding to runtime changes and Reflection offers the functionality to dynamically access and manipulate properties of objects during runtime. Combining these concepts turned out to be the most suitable solution for my case.</p><p>Let me demonstrate my approach, code-wise.</p><p>I set up a function that will take the input HTML string and API query information and return the processed HTML string which will be returned to client side.</p><pre>public async Task&lt;string&gt; GenerateCustomPDFDocument(DocumentPdfForCustomTemplateQuery request)<br>{<br>    try<br>    {<br>     // mapping API query types against modules in a dictionary<br>       var moduleQueryTypes = new Dictionary&lt;string, Type&gt;<br>       {<br>           { nameof(ModuleNames.purchaseOrders), typeof(GetAllPurchaseOrderQuery) },<br>           { nameof(ModuleNames.saleOrders), typeof(GetAllSaleOrdersQuery) }<br>       };<br><br>    // getting the data type of API query against request from previous dictionary<br>       if (moduleQueryTypes.TryGetValue(request.ModuleName, out var dataType))<br>       {<br>           // preparing dynamic API query and response<br>            dynamic query = JsonConvert.DeserializeObject(request.JsonParams, dataType);<br>            dynamic response = null;<br><br>          // making API call according to request<br>            switch (request.ModuleName)<br>            {<br>                case nameof(ModuleNames.purchaseOrders):<br>                response = await _purchaseApiService.GetAllOrdersAsync(query);<br>                break;<br><br>                case nameof(ModuleNames.saleOrders):<br>                response = await _saleApiService.GetAllOrdersAsync(query);<br>                break;<br>             }<br><br>          // casting data and message from API response (will be casted on runtime only)<br>           var data = response?.Item1;<br><br>          // generating and returning string if API response have any data<br>           if (data != null)<br>           {<br>                templateHtmlVM = request.TemplateHtml;<br>                string finalHtml = BindCustomTemplateWithData(data, request.htmlTemplate);<br><br>                return finalHtml;<br>            }<br>          }<br>            return &quot;&quot;;<br>       }<br>       catch (Exception e)<br>       {<br>            return e.Message;<br>       }<br>      }</pre><p>Lets break down each portion.</p><pre>var moduleQueryTypes = new Dictionary&lt;string, Type&gt;<br>{<br>    { nameof(ModuleNames.purchaseOrders), typeof(GetAllPurchaseOrderQuery) },<br>    { nameof(ModuleNames.saleOrders), typeof(GetAllSaleOrdersQuery) }<br>};</pre><p>A dictionary named moduleQueryTypes is created to map module names to their corresponding query types. This is used to determine the type of query to be constructed dynamically based on the request.ModuleName.</p><pre>if (moduleQueryTypes.TryGetValue(request.ModuleName, out var dataType))<br>{<br>    dynamic query = JsonConvert.DeserializeObject(request.JsonParams, dataType);<br>    dynamic response = null;</pre><p>This section checks if the provided request.ModuleName exists in the moduleQueryTypes dictionary. If it does, it retrieves the associated query type (dataType) and deserializes the JSON parameters (request.JsonParams) into a dynamic query object.</p><pre>switch (request.ModuleName)<br>{<br>    case nameof(ModuleNames.purchaseOrders):<br>        response = await _purchaseApiService.GetAllOrdersAsync(query);<br>        break;<br><br>    case nameof(ModuleNames.saleOrders):<br>        response = await _saleApiService.GetAllOrdersAsync(query);<br>        break;<br>}</pre><p>This switch statement to determine the specific API service method to call based on the request.ModuleName and stores the response in the response variable.</p><pre>var data = response?.Item1;<br>if (data != null)<br>{<br>    templateHtmlVM = request.TemplateHtml;<br>    string finalHtml = BindCustomTemplateWithData(data, request.htmlTemplate);<br>    return finalHtml;<br>}</pre><p>The data variable is assigned from the responseas a dynamic entity. The method BindCustomTemplateWithData is called to generate a string based on the data. The result is then returned as an HTML string (finalHtml). This method leverages dynamic binding, casting query type on runtime and storing the response as a dynamic variable and sending it to BindCustomTemplateWithData to process.</p><p>TheBindCustomTemplateWithData method leverages the concept of Reflection to process the metadata of the response and append to the HTML string.</p><pre>private string BindCustomTemplateWithData&lt;T&gt;(T entity, string HtmlTemplate)<br>{<br>    try<br>    {<br>      // Getting the properties of the entity using reflection<br>       PropertyInfo[] properties = typeof(T).GetProperties();<br><br>      // Binding document information dynamically <br>       foreach (var property in properties)<br>       {<br>           // Getting value and system name using reflection<br>           object value = property.GetValue(entity);<br>           CustomSystemNameAttribute attribute = property.GetCustomAttribute&lt;CustomSystemNameAttribute&gt;();<br>           string systemName = attribute?.SystemName;<br><br>           // Replace placeholders in the HTML template dynamically<br>           HtmlTemplate = HtmlTemplate.Replace($&quot;{{{{{systemName}}}}}&quot;, GetFormattedValue(value));<br>       }<br><br>       return HtmlTemplate;<br>      }<br>      catch (Exception e)<br>      {<br>           return e.Message;<br>      }<br>  }</pre><p>Firstly, the method uses reflection to get an array of PropertyInfo objects representing the properties of the generic type T. Then, iterates over every property and catches their value as object and the assigned systemName from theirCustomSystemNameAttributeas string. Then, It dynamically replaces placeholders in the HTML template with the corresponding values from the entity. The placeholder is identified by the system name obtained from the custom attribute. The helper method GetFormattedValue is responsible for formatting values based on their type.</p><pre> private string GetFormattedValue(object value)<br> {<br>    if (value == null) return &quot;&quot;;<br>    if (value is decimal decimalValue)<br>        return decimalValue &gt;= 0 ? value.ToString() : &quot;N/A&quot;;<br>         <br>    return value.ToString();<br> }</pre><p>Finally, I get a system that can make random API call depending on the request and process the given HTML string with the data from the API response on runtime. Simple and precise.</p><p>Dynamic data binding, as exemplified in this scenario, is an essential concept in software development, particularly in scenarios where the structure of data is not predefined or known until runtime. In traditional static binding, the connections between data and user interface elements are established at compile-time. However, dynamic data binding allows for these connections to be determined and adjusted during runtime.</p><p>Reflection, a fundamental feature in C#, can assist to inspect and interact with the metadata of types and objects during runtime. This runtime introspection can enable applications to navigate through object properties, retrieve values, and make decisions based on the metadata available at runtime.</p><p>The combination of dynamic data binding and reflection proves to be a versatile and robust solution for my scenario. The code demonstrates the ability to make API calls to different services dynamically, handle responses of varying structures, and bind the data to a client-specified HTML template, all without prior knowledge of the data structure at compile-time. Pretty interesting, right?</p><p>Find more about Reflection <a href="https://learn.microsoft.com/en-us/dotnet/framework/reflection-and-codedom/reflection">here</a>.</p><p>Adios.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44680afcf7a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Transactions on EF Core]]></title>
            <link>https://medium.com/@mim.aminakhatun/transactions-on-ef-core-714482e8b564?source=rss-6c6078afdeb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/714482e8b564</guid>
            <dc:creator><![CDATA[Amina Mim]]></dc:creator>
            <pubDate>Fri, 06 Jan 2023 18:18:41 GMT</pubDate>
            <atom:updated>2023-01-06T18:18:41.801Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SGAlhPoXsmFi4Td_" /><figcaption>Photo by <a href="https://unsplash.com/@towfiqu999999?utm_source=medium&amp;utm_medium=referral">Towfiqu barbhuiya</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Let me get started with an example scenario.</p><p>Imagine you have a simple order management system that takes an order from a customer and prints an invoice for the customer’s total orders. Your database has two tables: Order &amp; Invoice. Each order from a customer will first create an order in the Order table and then, depending on the order data, an invoice will be created in the Invoice table.</p><p>A sample code snippet for this system can be like this:</p><pre>try<br>{<br>    using var context = OrderManagementContext();<br>    var Order = new Order<br>            {<br>                CustomerName = &quot;Amina&quot;,<br>                Item = &quot;Book&quot;,<br>                Quantity= 1,<br>                Price = 500<br>            };<br>     context.Add(Order);<br>     context.SaveChanges();<br><br>     var Invoice = new Invoice<br>            {<br>                To = Order.CustomerName,<br>                Price = context.Order.where(c =&gt; c.CustomerName == Order.CustomerName).Sum(c =&gt; c.Price)<br>            };<br>     context.Add(Invoice);<br>     context.SaveChanges();<br>    <br>    return true;<br>}<br>catch(Exception ex)<br>{<br>    return false;<br>}</pre><p>A very simple case.</p><p>Now, imagine while processing a customer’s order, something unexpected occurs after saving the order but before creating the invoice. An order will be created on the Order table but due to the exception, no invoice will be created. After getting a failed message, the customer places an order again. As there was already an order placed by this customer, the invoice will find two orders of price 500 and save 1000 instead of 500. That&#39;s going to make the customer very confused, right?</p><p>In development, there will be many cases where we will need to perform multiple operations on a database, and all served as a single logical unit of work. If a transaction of multiple operations is done, all the operations either has to be successfully committed to the database or rolled back to previous state to prevent any inconvenience between the data. Entity Framework transactions are a part of its internal architecture. As we know, EF core context tracks the entities. All the operations performed on the entities are performed on in-memory objects. After performing the operations, when SaveChanges() is called, all those changes are stored in the underlying database. When we commit a transaction, all the tracked changes are performed in the database altogether.</p><p>If we consider the above scenario, we are performing two operations on the database and both serve as a single logic. Thus, making this a perfect scenario to use the leverage of transaction. Firstly, we can use BeginTransaction() before creating an order, which will work as a starting point for our transaction.</p><pre>try<br>{<br>    using var context = OrderManagementContext();<br>    context.Database.BeginTransaction();<br><br>    var Order = new Order<br>            {<br>                CustomerName = &quot;Amina&quot;,<br>                Item = &quot;Book&quot;,<br>                Quantity= 1,<br>                Price = 500<br>            };<br>     context.Add(Order);<br>     context.SaveChanges();<br><br>     var Invoice = new Invoice<br>            {<br>                To = Order.CustomerName,<br>                Price = context.Order.where(c =&gt; c.CustomerName == Order.CustomerName).Sum(c =&gt; c.Price)<br>            };<br>     context.Add(Invoice);<br>     context.SaveChanges();<br>    <br>    return true;<br>}<br>catch(Exception ex)<br>{<br>    return false;<br>}</pre><p>Now, each time the SaveChanges() is called, it will track the in-memory changes made within the entity. After we have created both Order and Invoice, then we can call Commit() for our transaction to actually make the tracked changes in the database.</p><pre>try<br>{<br>    using var context = OrderManagementContext();<br>    context.Database.BeginTransaction();<br><br>    var Order = new Order<br>            {<br>                CustomerName = &quot;Amina&quot;,<br>                Item = &quot;Book&quot;,<br>                Quantity= 1,<br>                Price = 500<br>            };<br>     context.Add(Order);<br>     context.SaveChanges();<br><br>     var Invoice = new Invoice<br>            {<br>                To = Order.CustomerName,<br>                Price = context.Order.where(c =&gt; c.CustomerName == Order.CustomerName).Sum(c =&gt; c.Price)<br>            };<br>     context.Add(Invoice);<br>     context.SaveChanges();<br>    <br>     context.Database.Commit();<br>    <br>     return true;<br> <br>}<br>catch(Exception ex)<br>{<br>    return false;<br>}</pre><p>Thus, it is guaranteed that both the order and invoice will be created properly on the database. Now, in case of any exceptions, we can use Rollback() to return to the entity’s previous state before this transaction started. That means even if an order is created but for some exception the invoice can not be created, the order will be reverted and will not be saved on the database.</p><pre>try<br>{<br>    using var context = OrderManagementContext();<br>    context.Database.BeginTransaction();<br><br>    var Order = new Order<br>            {<br>                CustomerName = &quot;Amina&quot;,<br>                Item = &quot;Book&quot;,<br>                Quantity= 1,<br>                Price = 500<br>            };<br>     context.Add(Order);<br>     context.SaveChanges();<br><br>     var Invoice = new Invoice<br>            {<br>                To = Order.CustomerName,<br>                Price = context.Order.where(c =&gt; c.CustomerName == Order.CustomerName).Sum(c =&gt; c.Price)<br>            };<br>     context.Add(Invoice);<br>     context.SaveChanges();<br>    <br>     context.Database.Commit();<br>    <br>     return true;<br> <br>}<br>catch(Exception ex)<br>{<br>    context.Database.Rollback();<br>    return false;<br>}</pre><p>Now, in case of any exception, the transaction will be rolled back to the same state as if it had never started. The customer will either have both order and invoice created, or nothing created at all.</p><p>A simple but very handy tool for transactional operations.</p><p>You can also create manual endpoints (known as Savepoints) for the transaction to roll back to. In that case, when the rollback happens, the transaction will not return to the beginning state but to the manual point that has been specified in the Rollback(). If we apply this in our scenario, it will look like:</p><pre>try<br>{<br>    using var context = OrderManagementContext();<br>    context.Database.BeginTransaction();<br><br>    var Order = new Order<br>            {<br>                CustomerName = &quot;Amina&quot;,<br>                Item = &quot;Book&quot;,<br>                Quantity= 1,<br>                Price = 500<br>            };<br>     context.Add(Order);<br>     context.SaveChanges();<br><br>    context.CreateSavepoint(&quot;OrderAdded&quot;);<br><br>     var Invoice = new Invoice<br>            {<br>                To = Order.CustomerName,<br>                Price = context.Order.where(c =&gt; c.CustomerName == Order.CustomerName).Sum(c =&gt; c.Price)<br>            };<br>     context.Add(Invoice);<br>     context.SaveChanges();<br>    <br>     context.Database.Commit();<br>    <br>     return true;<br> <br>}<br>catch(Exception ex)<br>{<br>    context.Database.RollbackToSavepoint(&quot;OrderAdded&quot;);<br>    return false;<br>}</pre><p>The transaction can be rolled back until last successful Savepoint (in this case, till OrderAdded). After coming to Savepoint, the transaction is in the same state as if the remaining part of transactions has not been executed yet. P.S. The save point feature may not be supported by some databases. In order to avoid any issue, it should be analyzed carefully to ensure that the feature is supported by the underlying database.</p><p>Hope this makes the concept of transactions a bit clearer. You can find more about EF Core transactions <a href="https://learn.microsoft.com/en-us/ef/core/saving/transactions"><em>here</em></a>.</p><p>Adios.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=714482e8b564" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Garbage Collection on .NET]]></title>
            <link>https://medium.com/@mim.aminakhatun/garbage-collection-on-net-be51dc1c6317?source=rss-6c6078afdeb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/be51dc1c6317</guid>
            <category><![CDATA[garbage-collection]]></category>
            <category><![CDATA[memory-management]]></category>
            <category><![CDATA[dotnet]]></category>
            <dc:creator><![CDATA[Amina Mim]]></dc:creator>
            <pubDate>Wed, 27 Jul 2022 19:21:30 GMT</pubDate>
            <atom:updated>2022-07-27T19:24:10.255Z</atom:updated>
            <content:encoded><![CDATA[<h3>Garbage Collection on .NET</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*k9MSinWTVYgC6VGwZc8iEw.png" /></figure><p>In current software development world, we, developers usually do not have to worry about the internal complexities of an application. We write codes, we run them, we get bugs, we fix them. We consider the time complexity, we keep in mind the best practices, we focus on whether the purpose being served or not by our software.<br>But that is just the surface level of a complex environment. Thanks to the .NET framework, we only have to think about what to do, rather than worrying about how it will be done. One beneath the surface level complexity is memory allocation and de-allocation. Memory is a crucial resource for any application. Our code continuously consumes and releases memory, but with the presence of <a href="https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/"><em>Garbage Collector</em></a>, a developer barely has to worry about memory management of his/her system and still write codes. Memory is automatically managed by <strong>GC</strong> that is usually hidden from a developer’s point of view. [<em>This can be considered as a real-life example of Abstraction</em>]. If you want to be aware of every aspects of your application, you have to have some minimum knowledge about how your application is utilizing memory resource.</p><p>So, let’s get some insights about garbage collection on .NET.</p><p>In our code, every time we create a new object (primitive or non-primitive type) it occupies some virtual memory address. The runtime reserves a contiguous region of address space when the execution starts. This reserved address space is called the managed heap where the memory addresses of the objects are stored. Our code keeps allocating memory till there is space left in this reserved address space. Now, say your system has low physical memory or your memory address is full or allocated objects on the managed heap has surpassed an acceptable threshold, what to do then? The obvious answer is to free up some memory by cleaning up the space that is occupied by the object that are no longer being used by your system. That’s usually when the Garbage Collector is triggered. It gives its name a literal meaning. It collects the objects that are considered ‘<em>garbage</em>’ to the application.</p><p>GC determines which objects are no longer being used by examining the application’s roots that is provided by the runtime. It creates a graph that contains all the objects that are reachable from the roots. Objects unreachable from the root is considered dead.</p><p>GC then releases the memory that has been allocated for them.</p><p>With each release, GC compacts the reachable objects in memory, freeing up the blocks of address spaces allocated to unreachable objects.</p><p>Once the memory for the reachable objects has been compacted, necessary pointer corrections are made so that the application’s roots point to the live objects in their new locations. If all the objects in the managed heap survive a collection, then there is no need for memory compaction.</p><p>Now, objects can survive a collection depending on their generation. In the initial stage of garbage collection, the managed heap is divided into three generations, <strong>Gen0</strong>, <strong>Gen1</strong>, and <strong>Gen2</strong>, so that long-lived and short-lived objects can be handled separately. The youngest and short-lived objects fall under Gen0 and the oldest and long-lived ones are in Gen2. Gen1 can be considered as a buffer from Gen0 to Gen2. Garbage collection occurs most frequently in Gen0. Most objects are reclaimed for garbage collection in this generation and usually don’t survive to the next generation. If memory scarcity is still present after a Gen0 collection, Gen1 collection is performed and depending on the memory condition, Gen2 after that. A generation 2 garbage collection is also known as a full garbage collection, because it reclaims objects in all generations.</p><p>That’s pretty much the basic of how garbage collection works. All the stages are usually hidden from a developer’s environment and is handled automatically by the runtime. But GC can also be triggered manually by calling the <a href="https://docs.microsoft.com/en-us/dotnet/api/system.gc.collect?view=net-6.0"><strong><em>GC.Collect()</em></strong></a> method, which should only happen in unique circumstances because garbage collection is an expensive process. An application is suspended completely when the GC execution starts. That’s why you need to have proper and thorough idea of what you are doing before calling <strong><em>GC.Collect()</em></strong>. However, there might still be need to reclaim memory for unmanaged resources (e.g. file handle, window handle, or network connection) where the GC does not have full compatibility. A solution to that can be the use of <a href="https://docs.microsoft.com/en-us/dotnet/api/system.idisposable.dispose?view=net-6.0"><strong><em>Dispose()</em></strong></a> method to explicitly clean up memory after the object is no longer in use.</p><p>Hope this makes garbage collection a little comprehensible. Whole GC process is pretty complex but .NET runtime is handling that automatically. We, as developers, only need to have the knowledge about how things beneath the surface is actually working, as <a href="https://en.wikipedia.org/wiki/Petyr_Baelish"><em>Lord Baelish</em></a> once famously said,</p><blockquote>“Knowledge is power.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J5sR1ZBpWF_otvrO0wVwzA.jpeg" /></figure><p>Adios.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be51dc1c6317" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Tiny Introduction of CI/CD]]></title>
            <link>https://medium.com/@mim.aminakhatun/a-tiny-introduction-of-ci-cd-1eebf67c3e92?source=rss-6c6078afdeb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/1eebf67c3e92</guid>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <dc:creator><![CDATA[Amina Mim]]></dc:creator>
            <pubDate>Sun, 26 Jun 2022 19:27:35 GMT</pubDate>
            <atom:updated>2022-06-26T19:27:35.056Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3ra8Zl1GfAvpjyvD9iHbfQ.png" /><figcaption>Continous Integration and Continous deploymemt</figcaption></figure><p>Imagine working on a software development team that continuously provides new features and there is a constant need for deployment. The team will have to develop multiple new feature concurrently and deploy them to a distribution channel in the fastest possible time. If you are the only developer who implements new features, then the traditional waterfall approach might be enough. But that’s not the most common case. There will be multiple developers working on different new features of the same project at the same time. Some of them might even work on different parts of the same feature, that leaves a scope for merge conflicts. Some might accidentally forget to test their code before committing, and that might result in a failed build. And what if there is an urgent notice to deploy the code to a production branch immediately, before you get the chance to manually test it?</p><p>That’s where the concept of CI/CD (continuous integration and continuous delivery) comes to the rescue.</p><p>From the developer committing his/her code to a shared repository to deploying the publish ready code, CI/CD automates much or all of the manual human intervention traditionally needed to get new code from a commit into production. It helps prevent merging errors, duplicated efforts and improves coding collaboration to create a better product.</p><p>CI/CD consists of two parts: continuous integration and continuous delivery.</p><p>In CI (<strong>Continuous Integration</strong>) part, commonly, a developer will commit some code to a version control system (like Git), which will trigger the CI process, where the code is built in a standard environment and tested automatically. This codebase uses a static code analysis tool to determine code quality. If the source code passes all checks, including the testing phase, the CI process will attempt to package or compile the code.</p><p>CD (<strong>Continuous</strong> <strong>Deployment</strong>) takes over where CI ends. If the builds and tests are successful, the final stage is to ensure that it can be deployed with everything it needs to deploy to any environment at any time. At the end of the pipeline, the code is deployed directly to the production environment according to the instructions provided.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*R2_-a2M52yOi7nUacR--kw.png" /><figcaption>CI/CD Pipeline</figcaption></figure><p>The primal reason to implement a CI/CD pipeline is to reduce the time taken for feedback on developed features. The less the time it takes to catch vulnerabilities, the better the chances to manage risk and mitigation properly. That lessens the hassle of an agile development environment to a great extent.</p><p>Automation always makes life easier, right?</p><p>Find more <a href="https://about.gitlab.com/topics/ci-cd/">Here.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1eebf67c3e92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IQueryable or IEnumerable?]]></title>
            <link>https://medium.com/@mim.aminakhatun/iqueryable-or-ienumerable-5c149d3f253b?source=rss-6c6078afdeb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c149d3f253b</guid>
            <category><![CDATA[databse]]></category>
            <category><![CDATA[net-core]]></category>
            <category><![CDATA[entityframework-core]]></category>
            <category><![CDATA[query]]></category>
            <dc:creator><![CDATA[Amina Mim]]></dc:creator>
            <pubDate>Sat, 18 Jun 2022 19:38:28 GMT</pubDate>
            <atom:updated>2022-07-22T16:07:36.261Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fx9r5HES7x0RLetE8QA7PQ.jpeg" /></figure><p>Let’s imagine a scenario.</p><p>Suppose you need a specific book from a local library shelf, which is on the second row. The title of the book is ‘<em>The Call of Cthulhu’</em> and it has a black hardback. The librarian does not speak the local language. If any student asks for a book, he just takes all books from the shelf and lets the student pick the book that s/he needs. Now, if you simply ask for the <em>‘The Call of Cthulhu’</em> book, he might take all the book from the whole shelf and let you pick the manuscript yourself. You will eventually get the book, but it will take more time and energy. Well, let’s imagine you know both the local language and the mother tongue of the librarian. Now, you can simply tell him to give you the black hardback book from the second shelf in his native language. He will deliver you the legends of the terror of <a href="https://en.wikipedia.org/wiki/Cthulhu"><em>Cthulhu</em> </a>in no time. As simple as that!</p><p>While dealing with huge amounts of data from external data store, many developers can face the same dilemma, while being totally oblivious to the problem itself.</p><p>IEnumerable and IQueryable both are used for data manipulation in LINQ from the database and collections. The IQueryable interface is a child of the IEnumerable interface, meaning IQuerable can do almost everything that IEnumerable can. But there is a huge benefit that comes with IQueryable while dealing with external data store. It is like telling the librarian to give you the specific book in his mother tongue. Let me clear this up with explanation:</p><p>IQueryable creates a query based on the given code at server side and sends only necessary data back to client. That means, you can write your code in C# and while executing, IQueryable will interpret your required data specifications in query language to the database. In the above scenario, it is similar to you telling the librarian to give you the black hard back book from the second shelf in his local language. He will give you only one book based on your query conditions. In .NET terms, the code will look like:</p><p><strong>IQueryable&lt;Book&gt; Book = _context.Book.Where(c =&gt; c.Color == ‘Black’ &amp;&amp; c.cover == ‘Hardback’);</strong></p><p>Which will be interpreted in SQL as:</p><p><strong>SELECT * FROM Book AS [c] WHERE [c].[ Color] == ‘Black’ AND [c].[ Cover] == ‘Hardback’</strong></p><p>By contrast, you can ask for the ‘The Call of Cthulhu’ book in local language. The librarian will give you all the book and let you pick your required book. That is similar to what IEnumerable does with a data store. It loads all the data in memory and then process it to get the required data. In .NET terms, you can write:</p><p><strong>IEnumerable&lt;Book&gt; Book = _context.Book.AsEnumerable().(c =&gt; c.color == ‘Black’ &amp;&amp; c.cover == ‘Hardback’);</strong></p><p>The corresponding SQL will be:</p><p><strong>SELECT * FROM Book AS [c]</strong></p><p>Then .NET will search in-memory.</p><p>So the difference between IEnumerable and IQueryable is mainly about where the filter logic is executed. One executes on the client side and the other executes on the database.</p><p>IEnumerable comes in handy when you are dealing with in memory data (e.g. list, array) where there is relatively fewer data to iterate over. But, when you have a large number of data to process (e.g. database), IEnumerable might not be the best option. IQueryable is much faster in this case. Nevertheless, IQueryable interprets the same C# code for the SQL server and for the PostgreSQL, which is a plus.</p><p>For LINQ to Object and LINQ to XML queries, IEnumerable is the better option. IQueryable is beneficial for LINQ to SQL queries.</p><p>From an application’s viewpoint, the specific type and structure of the original source data is not important. The application always sees the source data as an IEnumerable&lt;T&gt; or IQueryable&lt;T&gt; collection. The only benefit is convenience. You as a developer need to decide what to use on your specific scenario for best outcome.</p><p>Hope this clears up some basic confusion about IEnumerable and IQueryable.</p><p>You can find more discussions <a href="https://social.msdn.microsoft.com/Forums/en-US/b749e6bf-6465-4ca0-8e3d-f220d779e7f2/whats-the-difference-between-enumerable-and-queryable?forum=aspcsharp">Here.</a></p><p>Adios.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c149d3f253b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>