<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mohammad Karimi</title>
    <description>The latest articles on Forem by Mohammad Karimi (@mohammadkarimi).</description>
    <link>https://forem.com/mohammadkarimi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1257140%2F5ce01fc6-68a2-4183-92d2-0e53664029d2.jpeg</url>
      <title>Forem: Mohammad Karimi</title>
      <link>https://forem.com/mohammadkarimi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mohammadkarimi"/>
    <language>en</language>
    <item>
      <title>Compilation steps in EF Core</title>
      <dc:creator>Mohammad Karimi</dc:creator>
      <pubDate>Thu, 29 Feb 2024 18:16:05 +0000</pubDate>
      <link>https://forem.com/mohammadkarimi/compilation-steps-in-ef-core-37d9</link>
      <guid>https://forem.com/mohammadkarimi/compilation-steps-in-ef-core-37d9</guid>
      <description>&lt;p&gt;In Entity Framework (EF) Core, the compilation phase is a crucial part of translating LINQ queries into SQL queries. The process involves the creation and execution of parameterized SQL queries based on the LINQ expressions. However, there are optimizations and features that can bypass or streamline this compilation process for improved performance.&lt;/p&gt;

&lt;p&gt;let's delve into each phase in a bit more detail:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;LINQ Expression Tree:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Entity Framework Core starts its journey with LINQ queries expressed as expression trees, a representation of code as data. These trees capture the structure and logic of queries.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Parameter Extraction and Cache Key:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Before executing a query, EF Core extracts parameters from the LINQ expression tree. These parameters are essential for creating a cache key, ensuring uniqueness for each distinct query.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Cache Check:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;EF Core checks its cache using the generated cache key. If a matching query and its result are found, this signifies that the query has been executed before. In such cases, EF Core can skip the compilation phase, directly utilizing the precompiled SQL and rapidly materializing objects.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Compilation Phase:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In scenarios where no match is found in the cache, EF Core enters the compilation phase. During this stage, it transforms the LINQ expression tree into parameterized Transact-SQL (T-SQL) statements. This process involves mapping LINQ expressions to corresponding SQL constructs.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Execution and Materialization:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With the compiled T-SQL in hand, EF Core executes the query against the underlying database. The result, typically a set of records, is then materialized into .NET objects or entities, aligning the relational data with the object-oriented model.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Cache Update:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Following a successful execution, EF Core updates its cache by storing the compiled query and its result. This caching strategy enhances future query performances, as subsequent executions of the same query can directly benefit from the cached, precompiled SQL.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;EF Compiled Query API:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Recognizing that certain queries are executed frequently, EF Core provides the &lt;code&gt;CompiledQuery&lt;/code&gt; API as a performance optimization tool. Developers can explicitly compile queries, creating reusable query objects. These compiled queries can be stored and reused across multiple executions, eliminating the need for redundant compilation and enhancing overall system efficiency.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Advantages of Using Compiled Queries:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Performance:&lt;/strong&gt; Compiled queries, whether managed by EF Core's caching mechanism or explicitly by developers, can significantly improve performance by reducing the overhead associated with repeated query compilation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reusability:&lt;/strong&gt; The ability to compile queries explicitly allows for their reuse across various parts of an application, promoting a more efficient and maintainable codebase.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Caching Benefits:&lt;/strong&gt; Caching not only minimizes compilation time but also serves as a strategy for storing frequently accessed queries and their results, further enhancing overall application responsiveness.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Understanding these phases and features within EF Core's query compilation process provides developers with insights into optimizing database interactions for better performance and responsiveness in their applications.&lt;/p&gt;

</description>
      <category>entityframework</category>
      <category>dotnetcore</category>
      <category>dotnet</category>
      <category>efcore</category>
    </item>
    <item>
      <title>Cross-Platform Diagnostic Tools for .NET Applications</title>
      <dc:creator>Mohammad Karimi</dc:creator>
      <pubDate>Mon, 05 Feb 2024 12:24:23 +0000</pubDate>
      <link>https://forem.com/mohammadkarimi/cross-platform-diagnostic-tools-for-net-applications-2366</link>
      <guid>https://forem.com/mohammadkarimi/cross-platform-diagnostic-tools-for-net-applications-2366</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
In the dynamic world of software development, understanding and monitoring the performance of your applications is crucial for delivering a seamless user experience. For .NET developers, having access to effective cross-platform diagnostic tools is invaluable. In this article, we'll take a closer look at three essential tools: dotnet-counters, dotnet-trace, and dotnet-dump.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;dotnet-counters: Overview of Application State&lt;/strong&gt;&lt;br&gt;
One of the fundamental diagnostic tools for .NET applications is dotnet-counters. This tool provides developers with a comprehensive overview of the current state of a running application. It covers essential metrics and performance indicators, allowing developers to gauge the health and efficiency of their code in real-time. By utilizing dotnet-counters, developers can identify potential issues and bottlenecks, making it an invaluable tool for both development and production environments.&lt;/p&gt;

&lt;p&gt;Installing and using &lt;code&gt;dotnet-counters&lt;/code&gt; is a straightforward process. Follow these steps to get started:&lt;/p&gt;

&lt;h3&gt;
  
  
  Installation:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ensure .NET SDK is Installed:&lt;/strong&gt;&lt;br&gt;
Before using &lt;code&gt;dotnet-counters&lt;/code&gt;, make sure you have the .NET SDK installed on your machine. You can download it from the official &lt;a href="https://dotnet.microsoft.com/download"&gt;Microsoft .NET website&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify Installation:&lt;/strong&gt;&lt;br&gt;
Open a terminal or command prompt and run the following command to verify that the .NET SDK is installed:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the installation is successful, you should see the installed version of the .NET SDK.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Install the dotnet-counters Tool:&lt;/strong&gt;
Run the following command to install the &lt;code&gt;dotnet-counters&lt;/code&gt; tool globally on your machine:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet tool &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--global&lt;/span&gt; dotnet-counters
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Verify Installation of dotnet-counters:&lt;/strong&gt;
Ensure that &lt;code&gt;dotnet-counters&lt;/code&gt; is installed correctly by running:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet-counters &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should display the installed version of &lt;code&gt;dotnet-counters&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Usage:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Run dotnet-counters:&lt;/strong&gt;
To use &lt;code&gt;dotnet-counters&lt;/code&gt; to monitor the state of a running application, navigate to the directory containing your .NET application and run:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet-counters monitor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Specify Process ID (PID):&lt;/strong&gt;
If you know the Process ID (PID) of the running application, you can directly monitor that process using:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet-counters monitor &lt;span class="nt"&gt;--process-id&lt;/span&gt; &amp;lt;PID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;View Available Counters:&lt;/strong&gt;
To see a list of available counters for the monitored process, use:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet-counters list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Filter Counters:&lt;/strong&gt;
You can filter counters based on categories. For example, to monitor only CPU-related counters, use:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet-counters monitor &lt;span class="nt"&gt;--category&lt;/span&gt; cpu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Stop Monitoring:&lt;/strong&gt;
To stop monitoring, press &lt;code&gt;Ctrl+C&lt;/code&gt; in the terminal or command prompt.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Additional Options:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--refresh-interval&lt;/code&gt;: Set the refresh interval for counter updates.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--format&lt;/code&gt;: Choose the output format (table, json, or csv).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet-counters monitor &lt;span class="nt"&gt;--process-id&lt;/span&gt; 1234 &lt;span class="nt"&gt;--category&lt;/span&gt; cpu &lt;span class="nt"&gt;--refresh-interval&lt;/span&gt; 1s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example monitors the CPU-related counters for the process with ID 1234, refreshing every second.&lt;/p&gt;

&lt;p&gt;Keep in mind that &lt;code&gt;dotnet-counters&lt;/code&gt; is a powerful tool, and you can customize its usage based on your specific monitoring needs. Adjust the parameters and options as necessary to gain insights into the application state effectively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;dotnet-trace: Detailed Performance and Event Monitoring&lt;/strong&gt;&lt;br&gt;
When a more in-depth analysis of performance and event monitoring is needed, dotnet-trace steps in. This diagnostic tool offers a detailed perspective on various aspects of application behavior. Developers can use dotnet-trace to track down specific events, understand the sequence of operations, and identify potential performance bottlenecks. This tool empowers developers to delve deeper into their codebase, making it an excellent choice for optimizing and fine-tuning application performance.&lt;/p&gt;

&lt;p&gt;Here's a guide on how to install and use &lt;code&gt;dotnet-trace&lt;/code&gt; for detailed performance and event monitoring:&lt;/p&gt;

&lt;h3&gt;
  
  
  Installation:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ensure .NET SDK is Installed:&lt;/strong&gt;&lt;br&gt;
Before using &lt;code&gt;dotnet-trace&lt;/code&gt;, make sure you have the .NET SDK installed on your machine. You can download it from the official &lt;a href="https://dotnet.microsoft.com/download"&gt;Microsoft .NET website&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify Installation:&lt;/strong&gt;&lt;br&gt;
Open a terminal or command prompt and run the following command to verify that the .NET SDK is installed:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the installation is successful, you should see the installed version of the .NET SDK.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Install the dotnet-trace Tool:&lt;/strong&gt;
Run the following command to install the &lt;code&gt;dotnet-trace&lt;/code&gt; tool globally on your machine:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet tool &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--global&lt;/span&gt; dotnet-trace
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Verify Installation of dotnet-trace:&lt;/strong&gt;
Ensure that &lt;code&gt;dotnet-trace&lt;/code&gt; is installed correctly by running:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet-trace &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should display the installed version of &lt;code&gt;dotnet-trace&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Usage:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Run dotnet-trace:&lt;/strong&gt;
To use &lt;code&gt;dotnet-trace&lt;/code&gt; for performance and event monitoring, navigate to the directory containing your .NET application and run:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet-trace collect
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Specify Process ID (PID):&lt;/strong&gt;
If you know the Process ID (PID) of the running application, you can directly collect traces for that process using:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet-trace collect &lt;span class="nt"&gt;--process-id&lt;/span&gt; &amp;lt;PID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;View Available Providers:&lt;/strong&gt;
To see a list of available event providers for tracing, use:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet-trace list-providers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Filter Events:&lt;/strong&gt;
You can filter events based on providers and keywords. For example, to trace only events related to garbage collection, use:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet-trace collect &lt;span class="nt"&gt;--providers&lt;/span&gt; Microsoft-Windows-DotNETRuntime &lt;span class="nt"&gt;--events&lt;/span&gt; GC
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Stop Tracing:&lt;/strong&gt;
To stop collecting traces, press &lt;code&gt;Ctrl+C&lt;/code&gt; in the terminal or command prompt.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Additional Options:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--duration&lt;/code&gt;: Set the duration for trace collection.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--output&lt;/code&gt;: Specify the output file for the collected traces.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--format&lt;/code&gt;: Choose the output format (nettrace or speedscope).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet-trace collect &lt;span class="nt"&gt;--process-id&lt;/span&gt; 1234 &lt;span class="nt"&gt;--providers&lt;/span&gt; Microsoft-Windows-DotNETRuntime &lt;span class="nt"&gt;--events&lt;/span&gt; GC &lt;span class="nt"&gt;--output&lt;/span&gt; trace.nettrace
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example collects traces related to garbage collection for the process with ID 1234 and saves the output to a file named &lt;code&gt;trace.nettrace&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Adjust the parameters and options based on your specific monitoring requirements, and explore the wealth of information that &lt;code&gt;dotnet-trace&lt;/code&gt; provides for optimizing and fine-tuning your .NET applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;dotnet-dump: Memory Insights On Demand&lt;/strong&gt;&lt;br&gt;
Memory-related issues are a common challenge in software development. dotnet-dump is a powerful diagnostic tool that allows developers to obtain a memory dump on demand or after a crash. This capability is invaluable for troubleshooting memory leaks, analyzing memory usage patterns, and identifying potential areas for improvement. By providing insights into the application's memory state, dotnet-dump aids developers in optimizing resource utilization and enhancing overall application stability.&lt;/p&gt;

&lt;p&gt;Here's a guide on how to install and use &lt;code&gt;dotnet-dump&lt;/code&gt; to obtain a memory dump on demand or after a crash:&lt;/p&gt;

&lt;h3&gt;
  
  
  Installation:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ensure .NET SDK is Installed:&lt;/strong&gt;&lt;br&gt;
Before using &lt;code&gt;dotnet-dump&lt;/code&gt;, make sure you have the .NET SDK installed on your machine. You can download it from the official &lt;a href="https://dotnet.microsoft.com/download"&gt;Microsoft .NET website&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify Installation:&lt;/strong&gt;&lt;br&gt;
Open a terminal or command prompt and run the following command to verify that the .NET SDK is installed:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the installation is successful, you should see the installed version of the .NET SDK.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Install the dotnet-dump Tool:&lt;/strong&gt;
Run the following command to install the &lt;code&gt;dotnet-dump&lt;/code&gt; tool globally on your machine:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet tool &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--global&lt;/span&gt; dotnet-dump
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Verify Installation of dotnet-dump:&lt;/strong&gt;
Ensure that &lt;code&gt;dotnet-dump&lt;/code&gt; is installed correctly by running:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet-dump &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should display the installed version of &lt;code&gt;dotnet-dump&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Usage:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Capture a Memory Dump:&lt;/strong&gt;
To capture a memory dump of a running .NET process, navigate to the directory containing your .NET application and run:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet-dump collect &lt;span class="nt"&gt;--process-id&lt;/span&gt; &amp;lt;PID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Capture a Memory Dump on Crash:&lt;/strong&gt;
If your application crashes, you can automatically capture a memory dump by using:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet-dump collect &lt;span class="nt"&gt;--process-id&lt;/span&gt; &amp;lt;PID&amp;gt; &lt;span class="nt"&gt;--trigger-once&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Analyze a Memory Dump:&lt;/strong&gt;
To analyze a previously captured memory dump, run:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet-dump analyze &amp;lt;DumpFilePath&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;List Loaded Assemblies:&lt;/strong&gt;
To view the loaded assemblies in a memory dump, use:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   dotnet-dump ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Quit dotnet-dump:&lt;/strong&gt;
To exit the dotnet-dump interactive mode, type &lt;code&gt;q&lt;/code&gt; and press &lt;code&gt;Enter&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Additional Options:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--output&lt;/code&gt;: Specify the output directory for the collected memory dump.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--timeout&lt;/code&gt;: Set the timeout for capturing a memory dump on crash.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet-dump collect &lt;span class="nt"&gt;--process-id&lt;/span&gt; 1234 &lt;span class="nt"&gt;--output&lt;/span&gt; ./dumps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example captures a memory dump for the process with ID 1234 and saves it to the &lt;code&gt;./dumps&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;Feel free to customize the parameters and options based on your specific requirements. &lt;code&gt;dotnet-dump&lt;/code&gt; is a powerful tool for diagnosing memory-related issues and gaining insights into the state of your .NET applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In the realm of .NET development, having access to cross-platform diagnostic tools is a game-changer. The trio of dotnet-counters, dotnet-trace, and dotnet-dump equips developers with the necessary instruments to monitor, analyze, and optimize their applications effectively. Whether it's gaining an overview of application state, delving into detailed performance metrics, or troubleshooting memory-related issues, these tools play a pivotal role in ensuring the robustness and efficiency of .NET applications. Incorporating these diagnostic tools into your development workflow will undoubtedly contribute to a more streamlined and reliable software development process.&lt;/p&gt;

</description>
      <category>aspnet</category>
      <category>csharp</category>
      <category>monitoring</category>
    </item>
    <item>
      <title>Top Tools for Load and Stress Testing</title>
      <dc:creator>Mohammad Karimi</dc:creator>
      <pubDate>Fri, 02 Feb 2024 09:35:32 +0000</pubDate>
      <link>https://forem.com/mohammadkarimi/top-tools-for-load-and-stress-testing-4p43</link>
      <guid>https://forem.com/mohammadkarimi/top-tools-for-load-and-stress-testing-4p43</guid>
      <description>&lt;p&gt;I think that Writing an article on load and stress testing tools can be a great resource for developers, testers, and anyone involved in ensuring the performance and scalability of software applications. Here's a more detailed exploration of the mentioned tools to help you:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhxnkgmswar715640565x.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhxnkgmswar715640565x.jpg" alt="Load Testing Tools" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Apache JMeter&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Overview:&lt;/strong&gt; Apache JMeter is a versatile and widely used open-source tool for performance testing. It allows users to simulate a variety of scenarios and protocols, including HTTP, HTTPS, FTP, SOAP, and more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Features:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;User-friendly GUI for test plan creation.&lt;/li&gt;
&lt;li&gt;Extensive reporting and analysis capabilities.&lt;/li&gt;
&lt;li&gt;Supports distributed testing for scalability.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;LoadRunner (by Micro Focus):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Overview:&lt;/strong&gt; LoadRunner is a comprehensive commercial tool designed for performance testing. It has been a staple in the industry for many years and supports a wide range of protocols.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Features:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Supports protocols such as HTTP, HTTPS, JDBC, and more.&lt;/li&gt;
&lt;li&gt;Scenario-based testing with various load models.&lt;/li&gt;
&lt;li&gt;Advanced reporting and analytics.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Gatling:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Overview:&lt;/strong&gt; Gatling is an open-source load testing tool that focuses on simplicity and scalability. It is scriptable in Scala and provides real-time reporting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Features:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Supports HTTP and WebSocket protocols.&lt;/li&gt;
&lt;li&gt;Scenario-based testing with a user-friendly DSL (Domain-Specific Language).&lt;/li&gt;
&lt;li&gt;Distributed testing capabilities.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;K6:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Overview:&lt;/strong&gt; K6 is an open-source load testing tool written in Go. It is known for its ease of use and supports JavaScript-based scripting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Features:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Simple command-line interface.&lt;/li&gt;
&lt;li&gt;Supports HTTP and WebSocket protocols.&lt;/li&gt;
&lt;li&gt;Can be used for both performance and load testing.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Artillery:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Overview:&lt;/strong&gt; Artillery is an open-source and extensible load testing tool built on Node.js. It focuses on simplicity and flexibility, allowing users to define testing scenarios using YAML.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Features:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Supports HTTP and WebSocket protocols.&lt;/li&gt;
&lt;li&gt;YAML-based scripting for defining complex scenarios.&lt;/li&gt;
&lt;li&gt;Real-time reporting during test execution.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Locust:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Overview:&lt;/strong&gt; Locust is an open-source load testing tool written in Python. It emphasizes ease of use and scalability, making it suitable for testing a wide range of applications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Features:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Scripted in Python, making it accessible for Python developers.&lt;/li&gt;
&lt;li&gt;Supports HTTP and provides a clean web-based UI.&lt;/li&gt;
&lt;li&gt;Distributed testing capabilities.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;BlazeMeter:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Overview:&lt;/strong&gt; BlazeMeter is a commercial load testing service based on Apache JMeter. It offers a cloud-based platform for easily executing and managing performance tests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Features:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Integrates with Apache JMeter.&lt;/li&gt;
&lt;li&gt;Provides cloud-based load testing services.&lt;/li&gt;
&lt;li&gt;Real-time reporting and analytics.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When selecting a tool, consider factors such as your specific testing requirements, ease of use, scripting capabilities, and reporting features. It's also important to evaluate whether the tool aligns with your technology stack and the type of applications you are testing (web applications, APIs, etc.).&lt;/p&gt;

</description>
      <category>testing</category>
      <category>loadtest</category>
      <category>stresstesting</category>
      <category>aspnet</category>
    </item>
    <item>
      <title>Simplifying API Calls with Refit in ASP.NET Core</title>
      <dc:creator>Mohammad Karimi</dc:creator>
      <pubDate>Fri, 26 Jan 2024 15:13:31 +0000</pubDate>
      <link>https://forem.com/mohammadkarimi/simplifying-api-calls-with-refit-in-aspnet-core-f6</link>
      <guid>https://forem.com/mohammadkarimi/simplifying-api-calls-with-refit-in-aspnet-core-f6</guid>
      <description>&lt;p&gt;Refit is a library in ASP.NET Core that simplifies the process of making HTTP requests to RESTful APIs. It allows you to define your API interfaces as C# interfaces and then use them as if they were local methods. This makes it easier to work with APIs in a type-safe manner. Here's a guide to help you get started on writing an article about using Refit in ASP.NET Core:&lt;/p&gt;

&lt;p&gt;Start by introducing the challenges of making HTTP requests to APIs in a traditional way in ASP.NET Core. Mention the verbosity and boilerplate code involved in handling HTTP requests and responses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Refit?&lt;/strong&gt;&lt;br&gt;
Briefly explain what Refit is and its main purpose. Emphasize that it simplifies the process of working with APIs by allowing developers to define API interfaces as C# interfaces.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting Up Refit&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install Refit Package
Guide the readers through the process of installing the Refit NuGet package in an ASP.NET Core project.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet add package Refit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Creating an API Interface&lt;/strong&gt;&lt;br&gt;
Show how to create an API interface using Refit. This involves defining methods that represent the different API endpoints.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Post
{
    public int Id { get; set; }
    public string Title { get; set; }
    public string Body { get; set; }
}

public interface IApiClient
{
    [Get("/api/posts")]
    Task&amp;lt;List&amp;lt;Post&amp;gt;&amp;gt; GetPosts();

    [Post("/api/posts")]
    Task&amp;lt;Post&amp;gt; CreatePost([Body] Post newPost);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Integrating Refit into ASP.NET Core
&lt;strong&gt;Registering Refit in Dependency Injection:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Explain how to register Refit in the ASP.NET Core dependency injection container. This is usually done in the &lt;code&gt;Startup.cs&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services.AddRefitClient&amp;lt;IApiClient&amp;gt;()
    .ConfigureHttpClient(c =&amp;gt; c.BaseAddress = new Uri("https://api.example.com"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Using Refit in Controllers or Services&lt;/strong&gt;&lt;br&gt;
Show examples of how to use the Refit interface in controllers or services. Emphasize the simplicity and type-safety that Refit brings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class PostsController : ControllerBase
{
    private readonly IApiClient _apiClient;

    public PostsController(IApiClient apiClient)
    {
        _apiClient = apiClient;
    }

    public async Task&amp;lt;IActionResult&amp;gt; GetPosts()
    {
        var posts = await _apiClient.GetPosts();
        return Ok(posts);
    }

    // ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Handling Authentication&lt;br&gt;
Explain how Refit handles authentication, whether it's through headers, tokens, or other authentication mechanisms.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Advanced Features&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Request and Response Logging&lt;/strong&gt;&lt;br&gt;
Show how to enable request and response logging for debugging purposes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services.AddRefitClient&amp;lt;IApiClient&amp;gt;()
    .AddHttpMessageHandler&amp;lt;YourLoggingHandler&amp;gt;();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Customizing Requests&lt;/strong&gt;&lt;br&gt;
Discuss how to customize requests using Refit attributes and options.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Summarize the benefits of using Refit in ASP.NET Core. Highlight the reduction in boilerplate code, improved type safety, and increased developer productivity when working with APIs.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>refit</category>
      <category>aspdotnet</category>
      <category>dotnetcore</category>
    </item>
    <item>
      <title>Safe guarding Sensitive Data in ASP.NET Core with Secret Manager</title>
      <dc:creator>Mohammad Karimi</dc:creator>
      <pubDate>Sun, 21 Jan 2024 17:00:19 +0000</pubDate>
      <link>https://forem.com/mohammadkarimi/safe-guarding-sensitive-data-in-aspnet-core-with-secret-manager-5c6l</link>
      <guid>https://forem.com/mohammadkarimi/safe-guarding-sensitive-data-in-aspnet-core-with-secret-manager-5c6l</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction:&lt;/strong&gt;&lt;br&gt;
In the realm of ASP.NET Core development, the need to manage sensitive data, such as application secrets, is paramount. To address this concern, the Secret Manager tool provides a secure and convenient solution, enabling developers to store and access sensitive information during the development phase without compromising security. In this article, we will delve into the workings of the Secret Manager tool, its setup, and how to seamlessly integrate it into your ASP.NET Core projects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding the Secret Manager Tool:&lt;/strong&gt;&lt;br&gt;
The Secret Manager tool operates by concealing the intricate details of where and how sensitive values are stored, allowing developers to utilize its capabilities without delving into implementation specifics. These app secrets, which should never be included in source control, are stored in a JSON file located in the local machine's user profile folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Windows File System Path:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;%APPDATA%\Microsoft\UserSecrets\&amp;lt;user_secrets_id&amp;gt;\secrets.json

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Enabling Secret Storage:&lt;/strong&gt;&lt;br&gt;
To enable the Secret Manager tool, the dotnet user-secrets init command is utilized, Or Click-Right on your project in Visual Studio and select Manage User Secrets Item.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet user-secrets init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command adds a UserSecretsId element within the project file's PropertyGroup. The UserSecretsId is a unique identifier associated with the project, and it is used to link secrets to the specific project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample Project File (XML):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;PropertyGroup&amp;gt;
  &amp;lt;TargetFramework&amp;gt;netcoreapp3.1&amp;lt;/TargetFramework&amp;gt;
  &amp;lt;UserSecretsId&amp;gt;79a3edd0-2092-40a2-a04d-dcb46d5ca9ed&amp;lt;/UserSecretsId&amp;gt;
&amp;lt;/PropertyGroup&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Setting a Secret:&lt;/strong&gt;&lt;br&gt;
Once the Secret Manager is initialized, secrets can be defined and associated with the project's UserSecretsId. For example, using the .NET CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet user-secrets set "ConnectionStrings:ApplicationDbContext" "..."

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Accessing a Secret&lt;/strong&gt;&lt;br&gt;
To access a secret within your ASP.NET Core project, follow these steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Register the User Secrets Configuration Source&lt;br&gt;
The User Secrets Configuration Provider registers the necessary configuration source with the .NET Configuration API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Read the Secret via the Configuration API&lt;br&gt;
Utilize the Configuration API to retrieve the secret securely within your application.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
The Secret Manager tool in ASP.NET Core provides a robust solution for managing sensitive information during the development phase. By seamlessly integrating with the .NET Configuration API, it ensures a secure and organized approach to handling app secrets. As developers, embracing tools like Secret Manager not only enhances security but also streamlines the development process by separating sensitive data from version-controlled source code.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>dotnetcore</category>
      <category>aspnet</category>
      <category>secutiry</category>
    </item>
    <item>
      <title>Let's dive a bit deeper into each step of the MediatR architecture</title>
      <dc:creator>Mohammad Karimi</dc:creator>
      <pubDate>Tue, 16 Jan 2024 07:11:42 +0000</pubDate>
      <link>https://forem.com/mohammadkarimi/lets-dive-a-bit-deeper-into-each-step-of-the-mediatr-architecture-22n9</link>
      <guid>https://forem.com/mohammadkarimi/lets-dive-a-bit-deeper-into-each-step-of-the-mediatr-architecture-22n9</guid>
      <description>&lt;p&gt;In MediatR architecture, each task is represented by a Request, sent to the corresponding Handler by the framework. However, MediatR acts like a pipeline, not directly passing the Request to the Handler.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fba7c7zz7f9npjormlkd3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fba7c7zz7f9npjormlkd3.png" alt="MediatR Framework" width="800" height="243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Instead, it goes through one or more middlewares, called Pipeline Behaviors, in three steps:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8xuaaxgr30ob7whtzb61.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8xuaaxgr30ob7whtzb61.png" alt="Pipeline Behavior in MadiatR" width="800" height="246"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Pre-Processing:&lt;/strong&gt;&lt;br&gt;
In the Pre-Processing step, the incoming Request is handed over to the Pre-processor. This is like the front door of the MediatR pipeline, where the Request is checked, validated, and possibly transformed before proceeding further.&lt;br&gt;
The Pre-processor can perform tasks such as ensuring the Request is in the right format, validating user input, or making any necessary adjustments to the Request data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Next Step:&lt;/strong&gt;&lt;br&gt;
Assuming the Pre-Processing step succeeds, the pipeline moves to the Next Step. Here, a delegate decides what comes next in the pipeline.&lt;br&gt;
This could be another middleware instance, adding another layer of processing, or the final destination, which is the Handler responsible for carrying out the core logic related to the Request.&lt;br&gt;
Think of it as passing the baton in a relay race; the Request smoothly moves to the next phase of processing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Post-Processing:&lt;/strong&gt;&lt;br&gt;
After the core logic (handled by the Handler) is executed, the pipeline reaches the Post-Processing step. This is the last stage before the result is sent back to the client.&lt;br&gt;
In Post-Processing, actions like logging the outcome, making final adjustments to the Response, or handling errors are performed.&lt;br&gt;
It's the place where you tie up loose ends, ensuring that everything is in order before the processed data is sent back to the client.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important Notes:&lt;/strong&gt;&lt;br&gt;
If there's an issue during the Pre-Processing (e.g., validation failure), the process immediately goes back, bypassing the Next and Post steps. This quick exit ensures that only valid Requests proceed through the entire pipeline.&lt;br&gt;
On the other hand, when everything goes smoothly, the logic is executed, and the Post-Processing step is not extensively used for validation-related tasks. It focuses more on actions needed after the Request is validated and processed.&lt;br&gt;
In essence, the MediatR pipeline is a carefully orchestrated sequence of steps, each playing a vital role in ensuring efficient and organized handling of Requests, from validation to execution and finalization.&lt;/p&gt;

</description>
      <category>softwaredevelopment</category>
      <category>dotnet</category>
      <category>csharp</category>
    </item>
    <item>
      <title>How DbContext pooling works!</title>
      <dc:creator>Mohammad Karimi</dc:creator>
      <pubDate>Mon, 15 Jan 2024 12:24:45 +0000</pubDate>
      <link>https://forem.com/mohammadkarimi/how-dbcontext-pooling-works-4goc</link>
      <guid>https://forem.com/mohammadkarimi/how-dbcontext-pooling-works-4goc</guid>
      <description>&lt;p&gt;If you are developing a high-performance ASP.NET Core application using Entity Framework Core, you may want to consider using DbContext pooling to reduce the overhead of creating and disposing of DbContext instances. DbContext pooling is a feature that allows EF Core to reuse the same context instance across requests, instead of creating a new one every time. This can improve performance by avoiding the cost of setting up various internal services and objects that are necessary for DbContext to work.&lt;/p&gt;

&lt;p&gt;In this blog post, I will explain how DbContext pooling works, how to enable it in your application, and what are some of the benefits and limitations of this feature.&lt;/p&gt;

&lt;p&gt;How DbContext pooling works!&lt;/p&gt;

&lt;p&gt;DbContext pooling works by reusing the same context instance across requests; this means that it’s effectively registered as a Singleton, and the same instance is reused across multiple requests (or DI scopes). However, unlike a normal Singleton, EF Core resets the state of the context before returning it to the pool, so that it behaves as if it was a new instance. This includes clearing any tracked entities, resetting any configuration options, and disposing of any internal resources.&lt;/p&gt;

&lt;p&gt;To enable DbContext pooling, you must replace the AddDbContext method with AddDbContextPool in your ConfigureServices method. For example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;services.AddDbContextPool&amp;lt;BlogContext&amp;gt;(options =&amp;gt; &lt;br&gt;
options.UseSqlServer(Configuration.GetConnectionString("BlogContext")));&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can also specify the maximum size of the pool by passing a second parameter to AddDbContextPool. The default size is 1024, which means that EF Core will keep up to 1024 context instances in the pool. If the pool size is exceeded, EF Core will return to creating new instances on demand.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo0gu60c6x782zdylcxbv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo0gu60c6x782zdylcxbv.jpg" alt="DbContext Pooling"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Benefits and limitations of DbContext pooling&lt;/p&gt;

&lt;p&gt;The main benefit of DbContext pooling is that it can improve performance by reducing the overhead of creating and disposing of DbContext instances. This can be especially noticeable in scenarios where you have many concurrent requests that use DbContext for short-lived operations. According to Microsoft’s documentation, DbContext pooling can reduce request latency by up to 50% compared to non-pooling.&lt;/p&gt;

&lt;p&gt;However, DbContext pooling also has some limitations that you need to be aware of. First of all, you need to make sure that your context does not hold any state that should not be shared across requests. For example, you should not use any static fields or properties in your context class, or store any data in the HttpContext.Items collection. You should also avoid using any custom services or objects that are not thread-safe or disposable in your context constructor or OnConfiguring method.&lt;/p&gt;

&lt;p&gt;Another limitation is that DbContext pooling does not work well with some features of EF Core that rely on modifying the context state at runtime. For example, you cannot use ChangeTracker.QueryTrackingBehavior or ChangeTracker.AutoDetectChangesEnabled properties to change the tracking behavior of your context after it has been created. You also cannot use a Database.SetCommandTimeout or Database.SetConnectionString methods to change the database connection settings of your context after it has been created. If you need to use these features, you should either disable DbContext pooling or use a separate non-pooled context for those operations.&lt;/p&gt;

&lt;p&gt;Finally, DbContext pooling may not have a significant impact on performance if your application does not use DbContext extensively, or if your database operations are long-running or complex. In these cases, the cost of creating and disposing of DbContext instances may be negligible compared to the cost of executing queries or saving changes. You should always measure the performance of your application before and after enabling DbContext pooling to see if it makes a difference for your scenario.&lt;/p&gt;

&lt;h1&gt;
  
  
  dotnet #entityframework #EF
&lt;/h1&gt;

</description>
      <category>database</category>
      <category>dotnet</category>
      <category>csharp</category>
    </item>
  </channel>
</rss>
