<?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: Sardar Mudassar Ali Khan</title>
    <description>The latest articles on Forem by Sardar Mudassar Ali Khan (@sardarmudassaralikhan).</description>
    <link>https://forem.com/sardarmudassaralikhan</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%2F907349%2F50ae3ada-611f-47de-b1ea-d0cb23176621.jpg</url>
      <title>Forem: Sardar Mudassar Ali Khan</title>
      <link>https://forem.com/sardarmudassaralikhan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sardarmudassaralikhan"/>
    <language>en</language>
    <item>
      <title>Mastering Connection Pooling with Dapper in ASP.NET Core Web API</title>
      <dc:creator>Sardar Mudassar Ali Khan</dc:creator>
      <pubDate>Thu, 26 Jun 2025 08:28:31 +0000</pubDate>
      <link>https://forem.com/sardarmudassaralikhan/mastering-connection-pooling-with-dapper-in-aspnet-core-web-api-2nf8</link>
      <guid>https://forem.com/sardarmudassaralikhan/mastering-connection-pooling-with-dapper-in-aspnet-core-web-api-2nf8</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In modern web development, one of the key challenges when working with databases is efficiently managing database connections. This is where &lt;strong&gt;connection pooling&lt;/strong&gt; comes in. Connection pooling is a method used to reuse database connections rather than repeatedly opening and closing connections for every query. This not only reduces overhead but also improves performance, especially in high-traffic applications.&lt;/p&gt;

&lt;p&gt;In this article, we will dive into how &lt;strong&gt;connection pooling&lt;/strong&gt; works, how &lt;strong&gt;Dapper&lt;/strong&gt; handles connection pooling by leveraging &lt;strong&gt;ADO.NET&lt;/strong&gt; in an &lt;strong&gt;ASP.NET Core Web API&lt;/strong&gt; application, and provide a step-by-step guide to implement it with a practical &lt;strong&gt;Products&lt;/strong&gt; model example.&lt;/p&gt;




&lt;h3&gt;
  
  
  1. &lt;strong&gt;What is Connection Pooling?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Connection pooling is a technique used to manage database connections efficiently. Instead of opening a new database connection every time your application needs to perform a query, a &lt;strong&gt;connection pool&lt;/strong&gt; maintains a set of reusable database connections. When the application needs a database connection, it gets one from the pool. Once the query is executed, the connection is returned to the pool instead of being closed, making it available for future use.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of Connection Pooling:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reduced Overhead&lt;/strong&gt;: Creating and closing connections can be expensive. By reusing open connections, the application avoids the overhead of repeatedly establishing new connections.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improved Performance&lt;/strong&gt;: With pooled connections, the application can reuse existing connections, leading to faster query execution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource Management&lt;/strong&gt;: Connection pooling helps limit the number of active connections, preventing the database from becoming overwhelmed with too many concurrent connections.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt;: As the application scales, connection pooling allows it to handle more simultaneous database requests efficiently.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In .NET, connection pooling is handled by &lt;strong&gt;ADO.NET&lt;/strong&gt;, which is automatically enabled when you use database providers like SQL Server or PostgreSQL.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. &lt;strong&gt;Why Use Connection Pooling in Your Application?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Connection pooling provides numerous benefits to your application:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Performance Boost&lt;/strong&gt;: With connection pooling, your application avoids the need to repeatedly connect and disconnect from the database. This can significantly improve the performance of high-traffic applications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimized Resource Usage&lt;/strong&gt;: Connection pooling limits the number of open database connections, preventing the server from being overloaded.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt;: As your application grows, connection pooling allows it to handle a higher volume of database requests without degrading performance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Dapper, as a lightweight Object-Relational Mapper (ORM) in the .NET ecosystem, leverages &lt;strong&gt;ADO.NET&lt;/strong&gt;'s connection pooling features. This makes it an ideal choice for high-performance applications that require efficient data access.&lt;/p&gt;




&lt;h3&gt;
  
  
  3. &lt;strong&gt;How Dapper Uses Connection Pooling&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Dapper does not directly manage connection pooling. Instead, it uses &lt;strong&gt;ADO.NET&lt;/strong&gt;, which automatically handles connection pooling for supported databases. When you create a database connection using &lt;strong&gt;Dapper&lt;/strong&gt;, it uses &lt;strong&gt;SQLConnection&lt;/strong&gt; (or &lt;strong&gt;NpgsqlConnection&lt;/strong&gt; for PostgreSQL), which is backed by &lt;strong&gt;ADO.NET&lt;/strong&gt;'s connection pooling mechanism.&lt;/p&gt;

&lt;p&gt;When an &lt;strong&gt;IDbConnection&lt;/strong&gt; is created using Dapper, connection pooling is enabled by the database provider (such as &lt;strong&gt;SQL Server&lt;/strong&gt; or &lt;strong&gt;PostgreSQL&lt;/strong&gt;), ensuring that the database connections are reused rather than opened and closed repeatedly. This happens automatically when using &lt;strong&gt;Dapper&lt;/strong&gt;, as long as you are using a connection string that enables pooling.&lt;/p&gt;




&lt;h3&gt;
  
  
  4. &lt;strong&gt;Setting Up Connection Pooling with Dapper in ASP.NET Core Web API&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Step 1: Install Required NuGet Packages
&lt;/h4&gt;

&lt;p&gt;First, you need to install the necessary NuGet packages. You need &lt;strong&gt;Dapper&lt;/strong&gt; and the database provider (SQL Server, PostgreSQL, etc.).&lt;/p&gt;

&lt;p&gt;For &lt;strong&gt;SQL Server&lt;/strong&gt;, install the following packages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet add package Dapper
dotnet add package Microsoft.Data.SqlClient
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For &lt;strong&gt;PostgreSQL&lt;/strong&gt;, install:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet add package Dapper
dotnet add package Npgsql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: Configure Connection Pooling in &lt;code&gt;appsettings.json&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;To enable connection pooling, you need to configure the connection string in your &lt;code&gt;appsettings.json&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;For &lt;strong&gt;SQL Server&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"ConnectionStrings"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"DefaultConnection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;Max Pool Size=100;Min Pool Size=10;"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For &lt;strong&gt;PostgreSQL&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"ConnectionStrings"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"DefaultConnection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Host=myserver;Database=mydatabase;Username=myuser;Password=mypassword;Pooling=true;MinPoolSize=10;MaxPoolSize=100;"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In these examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Max Pool Size&lt;/code&gt;&lt;/strong&gt;: Specifies the maximum number of connections allowed in the pool.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Min Pool Size&lt;/code&gt;&lt;/strong&gt;: Specifies the minimum number of connections to keep open in the pool.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Pooling=true&lt;/code&gt;&lt;/strong&gt;: Enables connection pooling (enabled by default).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Step 3: Set Up Dependency Injection for Dapper
&lt;/h4&gt;

&lt;p&gt;Now, configure &lt;strong&gt;Dapper&lt;/strong&gt; in your &lt;code&gt;Program.cs&lt;/code&gt; (ASP.NET Core 6.0 or later) or &lt;code&gt;Startup.cs&lt;/code&gt; (for earlier versions).&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Program.cs&lt;/strong&gt; (for ASP.NET Core 6.0 and later):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Microsoft.Data.SqlClient&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// For SQL Server&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Dapper&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;System.Data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WebApplication&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Add services to the container.&lt;/span&gt;
&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddControllers&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Register the SQL connection with connection pooling&lt;/span&gt;
&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddScoped&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IDbConnection&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;sp&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SqlConnection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Configuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetConnectionString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"DefaultConnection"&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// For SQL Server&lt;/span&gt;
    &lt;span class="c1"&gt;// new NpgsqlConnection(builder.Configuration.GetConnectionString("DefaultConnection"))); // For PostgreSQL&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;UseHttpsRedirection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;UseAuthorization&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapControllers&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we are configuring an &lt;strong&gt;IDbConnection&lt;/strong&gt; to be injected into the controller. This ensures that Dapper will use a pooled connection when interacting with the database.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 4: Create CRUD Operations for Products
&lt;/h4&gt;

&lt;p&gt;Now let’s create the &lt;strong&gt;Product&lt;/strong&gt; model and implement &lt;strong&gt;CRUD&lt;/strong&gt; operations using Dapper in a controller.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Dapper&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Microsoft.AspNetCore.Mvc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;System.Data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;YourNamespace.Controllers&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"api/[controller]"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;ApiController&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductsController&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ControllerBase&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;IDbConnection&lt;/span&gt; &lt;span class="n"&gt;_dbConnection&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Constructor injection of IDbConnection&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;ProductsController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IDbConnection&lt;/span&gt; &lt;span class="n"&gt;dbConnection&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;_dbConnection&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dbConnection&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// GET: api/products&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;HttpGet&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IActionResult&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"SELECT * FROM Products"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_dbConnection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;QueryAsync&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// GET: api/products/5&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;HttpGet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{id}"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IActionResult&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"SELECT * FROM Products WHERE Id = @Id"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_dbConnection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;QueryFirstOrDefaultAsync&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;NotFound&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// POST: api/products&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;HttpPost&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IActionResult&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;Create&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;FromBody&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;Product&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"INSERT INTO Products (Name, Price, StockQuantity, Description) VALUES (@Name, @Price, @StockQuantity, @Description)"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_dbConnection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ExecuteAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;BadRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Failed to create product"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;CreatedAtAction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;nameof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// PUT: api/products/5&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;HttpPut&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{id}"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IActionResult&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;Update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;FromBody&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;Product&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"UPDATE Products SET Name = @Name, Price = @Price, StockQuantity = @StockQuantity, Description = @Description WHERE Id = @Id"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_dbConnection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ExecuteAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StockQuantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Description&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;NotFound&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;NoContent&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// DELETE: api/products/5&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;HttpDelete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{id}"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IActionResult&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;Delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"DELETE FROM Products WHERE Id = @Id"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_dbConnection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ExecuteAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;NotFound&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;NoContent&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dapper’s &lt;code&gt;QueryAsync&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;ExecuteAsync&lt;/code&gt;&lt;/strong&gt; methods are used to perform database queries and commands.&lt;/li&gt;
&lt;li&gt;We inject the &lt;strong&gt;&lt;code&gt;IDbConnection&lt;/code&gt;&lt;/strong&gt; instance that uses connection pooling into the controller to interact with the database efficiently.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  5. &lt;strong&gt;Best Practices for Connection Pooling&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;While connection pooling is enabled by default in ADO.NET, here are some best practices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reuse Connections&lt;/strong&gt;: Avoid opening and closing connections unnecessarily. Reuse open connections for multiple queries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Minimize Connection Lifetime&lt;/strong&gt;: Keep the connection open only as long as necessary. Use &lt;code&gt;using&lt;/code&gt; statements to ensure connections are properly disposed of.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adjust Pool Size&lt;/strong&gt;: Depending on the load, adjust &lt;code&gt;Max Pool Size&lt;/code&gt; and &lt;code&gt;Min Pool Size&lt;/code&gt; to ensure the optimal number of connections.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monitor the Pool&lt;/strong&gt;: Regularly monitor connection pool usage to detect any issues like connection exhaustion or bottlenecks.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  6. &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In this article, we've explored how to implement &lt;strong&gt;connection pooling&lt;/strong&gt; using &lt;strong&gt;Dapper&lt;/strong&gt; in an &lt;strong&gt;ASP.NET Core Web API&lt;/strong&gt;. By leveraging ADO.NET's built-in connection pooling, Dapper automatically reuses database connections, improving the performance and scalability of your application.&lt;/p&gt;

&lt;p&gt;We also created a &lt;strong&gt;Products&lt;/strong&gt; model and implemented &lt;strong&gt;CRUD operations&lt;/strong&gt; using Dapper, providing a clear and efficient approach to database access in an API.&lt;/p&gt;

&lt;p&gt;With connection pooling enabled, your application will handle database operations more efficiently, reducing overhead and allowing it to scale gracefully. By following the best practices outlined in this article, you can ensure that your application makes optimal use of database connections, providing faster and more reliable responses for users.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>devops</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Why Your Azure DevOps Pipeline Might Not Be Triggering Automatically and How to Fix It</title>
      <dc:creator>Sardar Mudassar Ali Khan</dc:creator>
      <pubDate>Tue, 24 Jun 2025 11:43:06 +0000</pubDate>
      <link>https://forem.com/sardarmudassaralikhan/why-your-azure-devops-pipeline-might-not-be-triggering-automatically-and-how-to-fix-it-1fh0</link>
      <guid>https://forem.com/sardarmudassaralikhan/why-your-azure-devops-pipeline-might-not-be-triggering-automatically-and-how-to-fix-it-1fh0</guid>
      <description>&lt;p&gt;When working with Azure DevOps for continuous integration and continuous deployment (CI/CD), you expect the pipeline to automatically trigger whenever there are changes pushed to your repository. However, sometimes pipelines don’t trigger as expected, causing frustration and delays in deployment. If you find that your pipeline is not being triggered when new changes are pushed to the branch, here are several reasons why this might happen and how to fix them.&lt;/p&gt;




&lt;h3&gt;
  
  
  1. &lt;strong&gt;Verify the Trigger Settings in the YAML Pipeline&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The first thing to check is whether the pipeline’s trigger settings are properly configured in the YAML file.&lt;/p&gt;

&lt;p&gt;In your pipeline YAML file, you should have something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;trigger&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;include&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;backend-iter-jedha-dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration specifies that the pipeline should only trigger when there are changes pushed to the &lt;code&gt;Truckoom-iter-jedha-dev&lt;/code&gt; branch. Here are things to check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Correct Branch&lt;/strong&gt;: Make sure that the branch you're pushing to is indeed the one specified in the &lt;code&gt;trigger&lt;/code&gt; section. If you’re pushing changes to a different branch, the pipeline won’t trigger.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;YAML Location&lt;/strong&gt;: Ensure the YAML file is in the correct location. Typically, it should be in the root directory of your repository, unless you have specified a different location. If it is in a subfolder, you may need to specify the path when setting up the pipeline in Azure DevOps.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;Check for Push Events&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Azure DevOps triggers builds based on changes pushed to the repository. If the push event isn’t happening as expected, the pipeline won’t trigger. Here’s what you can do:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Confirm Commits&lt;/strong&gt;: Ensure that your push has actually occurred and that the branch you’re pushing to is &lt;code&gt;Truckoom-iter-jedha-dev&lt;/code&gt;. You can check this by looking at your Git commit history.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Check the Git Log&lt;/strong&gt;: You can run &lt;code&gt;git log&lt;/code&gt; to ensure that your changes are committed and pushed to the right branch. If you've pushed to a different branch or accidentally pushed to a remote branch, the pipeline won’t trigger for the intended branch.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. &lt;strong&gt;Ensure Proper Configuration of Azure DevOps Pipeline Triggers&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In Azure DevOps, there are two main types of triggers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CI Triggers (Continuous Integration)&lt;/strong&gt;: This is the trigger you’re most likely using, and it fires when changes are pushed to your repository.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;PR Triggers (Pull Request)&lt;/strong&gt;: This trigger is activated when a pull request is created, updated, or merged.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s how to check your CI trigger settings:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;strong&gt;Azure DevOps &amp;gt; Pipelines &amp;gt; [Your Pipeline] &amp;gt; Edit&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Ensure that the &lt;code&gt;trigger&lt;/code&gt; section is correctly configured, and that it points to the correct branch.&lt;/li&gt;
&lt;li&gt;If you're using PR triggers, ensure that the pipeline is configured to also trigger for PR events.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  4. &lt;strong&gt;Branch and Commit History&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you recently renamed or switched branches, ensure that your local and remote branches are properly synced. Here’s what to check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Branch Synchronization&lt;/strong&gt;: Make sure the remote branch is up-to-date and matches the branch you expect the pipeline to trigger for. You can run &lt;code&gt;git branch -r&lt;/code&gt; to check the remote branches and &lt;code&gt;git pull&lt;/code&gt; to make sure your local branch is synchronized.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Detached Commits&lt;/strong&gt;: Ensure that commits have been successfully pushed and are not in a detached HEAD state.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. &lt;strong&gt;Check Permissions and Access&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Sometimes, pipeline triggers might fail due to access or permission issues. Ensure that the pipeline has the necessary permissions to listen for changes and trigger the build. Here’s how:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pipeline Permissions&lt;/strong&gt;: Go to &lt;strong&gt;Project Settings &amp;gt; Pipelines&lt;/strong&gt; and check if there are any restrictions or permissions that might be blocking the trigger.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;User Access&lt;/strong&gt;: Ensure that the user pushing the changes has permission to trigger builds in the pipeline.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  6. &lt;strong&gt;Test the Pipeline by Triggering It Manually&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you’ve confirmed that everything is set up correctly, try manually triggering the pipeline. This will help you understand if there’s an issue with the pipeline itself or with the trigger configuration.&lt;/p&gt;

&lt;p&gt;To manually trigger a pipeline in Azure DevOps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;strong&gt;Pipelines &amp;gt; [Your Pipeline] &amp;gt; Run Pipeline&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Check if the build completes successfully. If it does, the issue might be with the trigger settings.&lt;/li&gt;
&lt;li&gt;If it fails, review the error messages to troubleshoot further.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  7. &lt;strong&gt;Check for Other Trigger Settings&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Azure DevOps has additional settings for triggers beyond what’s configured in the YAML file. These settings are located under &lt;strong&gt;Project Settings &amp;gt; Pipelines &amp;gt; Triggers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here are some things to verify:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pipeline Trigger Settings&lt;/strong&gt;: Make sure there are no additional filters applied to the branch, repository, or file paths that could be causing the pipeline not to trigger.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multiple Branches or Repositories&lt;/strong&gt;: If you’re working in a multi-branch or multi-repository pipeline, make sure that the correct branch is being watched.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  8. &lt;strong&gt;Verify the Azure DevOps Agent and Build Queues&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Another issue that might prevent the pipeline from triggering is a problem with the Azure DevOps agent or build queues.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Self-hosted Agents&lt;/strong&gt;: If you’re using a self-hosted agent, make sure it is running and is correctly configured to handle the pipeline build. You can check the status of the agent in &lt;strong&gt;Project Settings &amp;gt; Agent Pools&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Agent Status&lt;/strong&gt;: If you are using a hosted agent (e.g., &lt;code&gt;ubuntu-latest&lt;/code&gt;), check that the agent is available and has the correct environment setup to handle the build.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  9. &lt;strong&gt;Check Pipeline History and Logs&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If the pipeline is still not triggering, take a look at the build history to see if there are any failed pipeline runs or errors logged that can provide more insight.&lt;/p&gt;

&lt;p&gt;Here’s what to do:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;strong&gt;Pipelines &amp;gt; [Your Pipeline] &amp;gt; Runs&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Look for any failed or canceled builds and check the logs for errors that might explain the failure to trigger.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  10. &lt;strong&gt;Contact Azure DevOps Support&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If none of the above solutions work, you may want to reach out to Azure DevOps support for further assistance. They can help you troubleshoot issues related to the pipeline triggers, permissions, or agent configurations.&lt;/p&gt;




&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Azure DevOps pipelines are a powerful tool for automating your build and deployment processes, but they can sometimes fail to trigger automatically when expected. By following the steps above, you should be able to troubleshoot common issues that prevent pipelines from triggering. Ensuring that your triggers are properly configured, your repository is up-to-date, and your pipeline settings are correct will go a long way in preventing such issues.&lt;/p&gt;

&lt;p&gt;If you continue to face problems, manual intervention or contacting support might be required. Hopefully, with the above steps, your pipeline will trigger as expected, allowing for seamless builds and deployments every time a change is pushed.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>azure</category>
      <category>azuredevops</category>
      <category>cloud</category>
    </item>
    <item>
      <title>How to Resolve NuGet Package Manager Issues with v3 API Downtime</title>
      <dc:creator>Sardar Mudassar Ali Khan</dc:creator>
      <pubDate>Thu, 08 May 2025 20:20:09 +0000</pubDate>
      <link>https://forem.com/sardarmudassaralikhan/how-to-resolve-nuget-package-manager-issues-with-v3-api-downtime-ico</link>
      <guid>https://forem.com/sardarmudassaralikhan/how-to-resolve-nuget-package-manager-issues-with-v3-api-downtime-ico</guid>
      <description>&lt;p&gt;If you're working with NuGet in Visual Studio and encountering issues due to the NuGet v3 API being temporarily unavailable, you're not alone. Many developers have experienced downtime with the NuGet v3 API, leading to errors and hindering package management workflows. Fortunately, there is a quick workaround to resolve these issues.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Understanding the Problem&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;NuGet, a popular package manager for .NET, allows developers to easily install, update, and manage third-party libraries and tools in their projects. The NuGet v3 API is one of the primary sources used to retrieve and manage these packages. However, due to occasional downtime or connectivity issues with the NuGet v3 API, developers may face difficulties when attempting to restore or manage packages.&lt;/p&gt;

&lt;p&gt;The error often manifests as a timeout or an inability to fetch the necessary resources from the v3 API. This is especially problematic when you’re in the middle of development and need access to specific packages.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Temporary Workaround: Switching to NuGet v2 API&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;While the NuGet v3 API is down, you can use the NuGet v2 API as an alternative. The v2 API is still operational and will allow you to continue working on your project without disruptions. Here’s how you can switch from the v3 to the v2 API in Visual Studio.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step-by-Step Guide to Switch to NuGet v2 API:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Open Visual Studio&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Launch Visual Studio, the IDE you are using for your .NET projects.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Navigate to NuGet Package Manager Settings&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Go to &lt;code&gt;Tools&lt;/code&gt; in the top menu.&lt;/li&gt;
&lt;li&gt;Select &lt;code&gt;NuGet Package Manager&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Choose &lt;code&gt;Package Manager Settings&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Change the Package Source URL&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;In the settings window, go to &lt;code&gt;Package Sources&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;You'll see the default NuGet source listed as &lt;code&gt;https://api.nuget.org/v3/index.json&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Change this URL to &lt;code&gt;https://www.nuget.org/api/v2/&lt;/code&gt; to switch to the v2 API.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Save and Close&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;After updating the URL, click &lt;code&gt;OK&lt;/code&gt; to save your settings.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Rebuild Your Project&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Clean your project and rebuild it. This will allow NuGet to start using the v2 API to restore and manage packages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once these steps are completed, NuGet will automatically use the v2 API, bypassing the downtime issues caused by the v3 API.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Why Switch to NuGet v2 API?&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The v2 API is older but still very reliable for managing packages. It allows for smoother transitions in cases of downtime, ensuring that your workflow remains uninterrupted. By using the v2 API, you can avoid the issues caused by API unavailability and continue your development efforts.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Additional Tips:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Clear the NuGet Cache&lt;/strong&gt;: If you face persistent issues even after switching the source, clearing the NuGet cache might help. This ensures that NuGet doesn’t use any outdated or corrupted cached data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To clear the cache, go to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Tools -&amp;gt; NuGet Package Manager -&amp;gt; Package Manager Settings -&amp;gt; Clear All NuGet Cache(s)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Check NuGet Status&lt;/strong&gt;: Keep an eye on the official NuGet status page to see when the v3 API is back online. The NuGet team regularly updates the page with the status of their API services.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Revert Back to v3 Once Restored&lt;/strong&gt;: Once the v3 API is back up and running, you can switch the URL back to the default v3 URL to take advantage of its enhanced features, such as better performance and newer functionalities.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;When the NuGet v3 API experiences downtime, it can bring your project’s package management to a halt. However, by quickly switching to the v2 API as a temporary solution, you can continue with your development without interruption. It’s a simple process that ensures your workflow remains intact while waiting for the v3 API to come back online. Always keep your NuGet settings up to date and stay informed about the status of the NuGet services to minimize disruptions in your development process.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>vscode</category>
      <category>visualstudio</category>
    </item>
    <item>
      <title>Resolving Ambiguous Method Call in AutoMapper with Dependency Injection in .NET</title>
      <dc:creator>Sardar Mudassar Ali Khan</dc:creator>
      <pubDate>Thu, 01 May 2025 15:56:29 +0000</pubDate>
      <link>https://forem.com/sardarmudassaralikhan/resolving-ambiguous-method-call-in-automapper-with-dependency-injection-in-net-7gh</link>
      <guid>https://forem.com/sardarmudassaralikhan/resolving-ambiguous-method-call-in-automapper-with-dependency-injection-in-net-7gh</guid>
      <description>&lt;p&gt;When working with .NET Core and AutoMapper for object mapping, you might encounter an issue where the call to &lt;code&gt;AddAutoMapper&lt;/code&gt; becomes ambiguous. This issue can arise from multiple overloads of the &lt;code&gt;AddAutoMapper&lt;/code&gt; method, which can lead to confusion for the compiler, making it difficult for it to decide which method to call.&lt;/p&gt;

&lt;p&gt;This article will walk you through the cause of this issue, explain how to resolve it, and offer best practices for integrating AutoMapper with Dependency Injection in .NET.&lt;/p&gt;




&lt;h3&gt;
  
  
  The Problem: Ambiguous Method Call
&lt;/h3&gt;

&lt;p&gt;In .NET, the &lt;code&gt;AddAutoMapper&lt;/code&gt; method is part of the &lt;code&gt;AutoMapper.Extensions.Microsoft.DependencyInjection&lt;/code&gt; package. It allows you to configure AutoMapper in the Dependency Injection (DI) container, making it available throughout your application.&lt;/p&gt;

&lt;p&gt;However, you may run into an error like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The call is ambiguous between the following methods or properties: 
'Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.AddAutoMapper(Microsoft.Extensions.DependencyInjection.IServiceCollection, params System.Reflection.Assembly[])' 
and 
'Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.AddAutoMapper(Microsoft.Extensions.DependencyInjection.IServiceCollection, params System.Reflection.Assembly[])'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This error occurs because the compiler cannot differentiate between two overloads of the &lt;code&gt;AddAutoMapper&lt;/code&gt; method, even though they appear identical. The two methods may be defined in different assemblies or versions, causing ambiguity.&lt;/p&gt;




&lt;h3&gt;
  
  
  Causes of the Issue
&lt;/h3&gt;

&lt;p&gt;There are a few reasons why this ambiguity might occur:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Conflicting Versions of &lt;code&gt;AutoMapper&lt;/code&gt; or Related Packages:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You may have multiple versions of the &lt;code&gt;AutoMapper&lt;/code&gt; or &lt;code&gt;AutoMapper.Extensions.Microsoft.DependencyInjection&lt;/code&gt; package in your project or solution. When different versions of these packages define the same method signature, the compiler is unable to determine which one to use.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Multiple Assemblies with Overlapping Definitions:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In larger applications or solutions, you may reference multiple assemblies that include the same method definitions. For example, if you are using AutoMapper in different projects within the same solution, this could cause the compiler to be confused about which method to use.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Incorrect or Redundant &lt;code&gt;using&lt;/code&gt; Directives:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If your code includes multiple &lt;code&gt;using&lt;/code&gt; statements for different namespaces that provide the same method overload, this can cause ambiguity. It is essential to ensure that you are only referencing the correct namespaces.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  How to Resolve the Issue
&lt;/h3&gt;

&lt;p&gt;Let’s take a look at several steps to resolve the ambiguity when calling &lt;code&gt;AddAutoMapper&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. &lt;strong&gt;Ensure Consistent Package Versions&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Ensure that all projects in your solution are using the same version of the &lt;code&gt;AutoMapper&lt;/code&gt; and &lt;code&gt;AutoMapper.Extensions.Microsoft.DependencyInjection&lt;/code&gt; packages. You can check and update the versions in your project files (&lt;code&gt;.csproj&lt;/code&gt;), or use the NuGet Package Manager to ensure consistency.&lt;/p&gt;

&lt;p&gt;Here’s how you can define the package version in the &lt;code&gt;.csproj&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;PackageReference&lt;/span&gt; &lt;span class="na"&gt;Include=&lt;/span&gt;&lt;span class="s"&gt;"AutoMapper.Extensions.Microsoft.DependencyInjection"&lt;/span&gt; &lt;span class="na"&gt;Version=&lt;/span&gt;&lt;span class="s"&gt;"12.0.0"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also run the following command in your terminal to update all packages to the latest stable versions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet add package AutoMapper.Extensions.Microsoft.DependencyInjection &lt;span class="nt"&gt;--version&lt;/span&gt; 12.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. &lt;strong&gt;Fix Namespace Conflicts&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Check your &lt;code&gt;using&lt;/code&gt; statements at the top of your files. You may have multiple namespaces that are defining the same method. Ensure that you are using only the correct namespace that contains the desired extension method.&lt;/p&gt;

&lt;p&gt;For example, make sure you're using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;AutoMapper&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and avoid redundant or conflicting namespaces that might include the same method signature.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. &lt;strong&gt;Explicitly Specify Method Parameters&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;To resolve ambiguity, you can explicitly specify which assembly you are using when calling &lt;code&gt;AddAutoMapper&lt;/code&gt;. AutoMapper allows you to specify the assemblies that should be scanned for mapping profiles.&lt;/p&gt;

&lt;p&gt;Instead of passing all assemblies, you can pass just the required one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddAutoMapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Startup&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Pass the type of your Startup class&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This helps reduce the ambiguity by ensuring that only one assembly is considered, which is often the root cause of the problem.&lt;/p&gt;

&lt;h4&gt;
  
  
  4. &lt;strong&gt;Clean and Rebuild the Solution&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;After making changes to your package versions or resolving any conflicts, it is always a good idea to clean and rebuild your solution. This ensures that all the assemblies and dependencies are correctly reloaded, and it clears any cached data.&lt;/p&gt;

&lt;p&gt;In Visual Studio, navigate to &lt;code&gt;Build&lt;/code&gt; &amp;gt; &lt;code&gt;Clean Solution&lt;/code&gt;, and then &lt;code&gt;Build&lt;/code&gt; &amp;gt; &lt;code&gt;Rebuild Solution&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Alternatively, you can run the following commands in your terminal:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. &lt;strong&gt;Use Dependency Injection Correctly&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;When configuring AutoMapper with Dependency Injection, ensure that you are passing only the necessary assemblies that contain the mapping profiles.&lt;/p&gt;

&lt;p&gt;Here’s an example of configuring AutoMapper in &lt;code&gt;Startup.cs&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;ConfigureServices&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IServiceCollection&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddAutoMapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Startup&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;  &lt;span class="c1"&gt;// Automatically scan the assembly where Startup is located&lt;/span&gt;
    &lt;span class="c1"&gt;// Other service configurations...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, &lt;code&gt;typeof(Startup)&lt;/code&gt; ensures that AutoMapper will scan the assembly where the &lt;code&gt;Startup&lt;/code&gt; class resides, avoiding unnecessary ambiguity.&lt;/p&gt;

&lt;h4&gt;
  
  
  6. &lt;strong&gt;Verify for Multiple Assembly References&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;If you’re working in a multi-project solution, make sure that the &lt;code&gt;AutoMapper&lt;/code&gt; package and the &lt;code&gt;AutoMapper.Extensions.Microsoft.DependencyInjection&lt;/code&gt; package are only referenced once in the entire solution.&lt;/p&gt;

&lt;p&gt;To check for conflicting references, examine your &lt;code&gt;obj&lt;/code&gt; and &lt;code&gt;bin&lt;/code&gt; folders, and ensure that there are no duplicate versions of the same assemblies. You can also use the following command to list the versions of installed packages:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;






&lt;h3&gt;
  
  
  Best Practices for Using AutoMapper with Dependency Injection
&lt;/h3&gt;

&lt;p&gt;Here are some best practices for using AutoMapper in your .NET applications to avoid issues like the one discussed above:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Centralize Profile Configuration:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Place your mapping profiles in a dedicated assembly or class and reference only that assembly when calling &lt;code&gt;AddAutoMapper&lt;/code&gt;. This improves organization and reduces ambiguity.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use &lt;code&gt;typeof()&lt;/code&gt; Instead of Passing Multiple Assemblies:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you are working with just one assembly, pass &lt;code&gt;typeof(Startup)&lt;/code&gt; or another central class as the argument to &lt;code&gt;AddAutoMapper&lt;/code&gt;. This is a clean and simple approach.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Review Your Dependencies Regularly:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ensure that you are not using multiple versions of the same package across different projects. Regularly update and audit your packages to avoid compatibility issues.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Test for Regression Issues:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When upgrading or downgrading packages, thoroughly test your application to ensure that changes do not break existing functionality, especially when dealing with third-party libraries like AutoMapper.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;An ambiguous method call in AutoMapper can be frustrating, but it’s a common issue that arises from conflicting package versions, redundant namespaces, and incorrect DI configuration. By following the steps outlined in this article, you can resolve the ambiguity and configure AutoMapper in a clean and effective way. Always ensure consistent package versions, resolve namespace conflicts, and follow best practices for Dependency Injection to ensure smooth integration of AutoMapper in your .NET applications.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>aspnet</category>
      <category>aspdotnet</category>
    </item>
    <item>
      <title>How to Resolve "The Process Cannot Access the File Because It Is Being Used by Another Process" Error in .NET Projects</title>
      <dc:creator>Sardar Mudassar Ali Khan</dc:creator>
      <pubDate>Thu, 01 May 2025 15:52:52 +0000</pubDate>
      <link>https://forem.com/sardarmudassaralikhan/how-to-resolve-the-process-cannot-access-the-file-because-it-is-being-used-by-another-process-1mo6</link>
      <guid>https://forem.com/sardarmudassaralikhan/how-to-resolve-the-process-cannot-access-the-file-because-it-is-being-used-by-another-process-1mo6</guid>
      <description>&lt;p&gt;When building or deploying a .NET project, developers may encounter the error message:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"Unable to copy file 'path\apphost.exe' to 'path\project.exe'. The process cannot access the file because it is being used by another process."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This error usually occurs when a file is locked by another running process, preventing the build or deployment from proceeding. In this article, we'll walk you through the causes of this issue and provide detailed steps on how to resolve it.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Understanding the Error&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The error happens when your development environment (e.g., Visual Studio, Visual Studio Code) attempts to overwrite or access a file (typically an executable file like &lt;code&gt;apphost.exe&lt;/code&gt; or &lt;code&gt;project.exe&lt;/code&gt;) while it is still being used by another process. This can occur if the application you're trying to build or deploy is already running, or if some background process (like the debugger or antivirus software) has locked the file.&lt;/p&gt;

&lt;p&gt;Here’s a breakdown of the error:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Source File:&lt;/strong&gt; The file in question (usually an executable like &lt;code&gt;.exe&lt;/code&gt; or &lt;code&gt;.dll&lt;/code&gt;) is located in the output directory (&lt;code&gt;bin\Debug\net8.0&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Target File:&lt;/strong&gt; The build process tries to copy the file to the project’s output directory but cannot because the file is in use.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Locked by Another Process:&lt;/strong&gt; The lock may be caused by running the application, debugging, or an external application.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Steps to Resolve the Error&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Follow these steps to identify the cause of the lock and free the file:&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;1. Close Any Running Application or Debugger&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The most common cause of this error is that your application is still running or being debugged. Ensure that the application you're trying to build or deploy is not running.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stop Debugging&lt;/strong&gt;: If you are debugging the application, stop the debugger by pressing &lt;strong&gt;Shift + F5&lt;/strong&gt; or clicking the &lt;strong&gt;Stop Debugging&lt;/strong&gt; button in your IDE.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Close the Application&lt;/strong&gt;: If the application is running outside the IDE (e.g., from a terminal or command prompt), close it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;2. End Any Related Processes Using Task Manager&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Sometimes, even after stopping the debugger or closing the application, the file remains locked by a background process. You can use Task Manager to forcefully end these processes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Press &lt;strong&gt;Ctrl + Shift + Esc&lt;/strong&gt; to open &lt;strong&gt;Task Manager&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Look under the &lt;strong&gt;Processes&lt;/strong&gt; tab for any processes related to your project (e.g., &lt;code&gt;DotNetCore-Angular-SocialMedia-App.exe&lt;/code&gt; or &lt;code&gt;dotnet&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Right-click the process and select &lt;strong&gt;End Task&lt;/strong&gt; to terminate it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This will release the file lock and allow you to proceed with the build.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;3. Clean and Rebuild the Project&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Old or temporary files can sometimes cause conflicts during the build process. By cleaning and rebuilding your project, you can ensure that there are no leftover artifacts blocking the build.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;In &lt;strong&gt;Visual Studio&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to &lt;strong&gt;Build &amp;gt; Clean Solution&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Then, go to &lt;strong&gt;Build &amp;gt; Rebuild Solution&lt;/strong&gt; to rebuild the project from scratch.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;In &lt;strong&gt;VS Code&lt;/strong&gt; or using the &lt;strong&gt;.NET CLI&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run the following commands:
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt; dotnet clean
 dotnet build
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;This will clear the &lt;code&gt;bin&lt;/code&gt; and &lt;code&gt;obj&lt;/code&gt; folders and rebuild the entire solution.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;4. Delete the Bin and Obj Folders Manually&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;If cleaning and rebuilding the project doesn’t resolve the issue, you can manually delete the &lt;code&gt;bin&lt;/code&gt; and &lt;code&gt;obj&lt;/code&gt; folders from your project directory.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to your project folder (e.g., &lt;code&gt;E:\SMAK-Angular-and-Dot-Net\NGCORE-BACKEND\DotNetCore-Angular-SocialMedia-App\&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Delete the &lt;code&gt;bin&lt;/code&gt; and &lt;code&gt;obj&lt;/code&gt; folders.&lt;/li&gt;
&lt;li&gt;Rebuild the project in your IDE or via the &lt;code&gt;.NET CLI&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This removes old assemblies, allowing your project to build cleanly.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;5. Use Process Explorer to Identify the Locking Process&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;If the file is still locked, you can use a tool like &lt;strong&gt;Process Explorer&lt;/strong&gt; (from Sysinternals) to identify which process is using the file.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Download and run &lt;strong&gt;Process Explorer&lt;/strong&gt; from the &lt;a href="https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer" rel="noopener noreferrer"&gt;Microsoft Sysinternals website&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Press &lt;strong&gt;Ctrl + F&lt;/strong&gt; to open the Find dialog, and search for the name of the file (e.g., &lt;code&gt;DotNetCore-Angular-SocialMedia-App.exe&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Process Explorer will show you the process that is locking the file.&lt;/li&gt;
&lt;li&gt;Right-click the process and choose &lt;strong&gt;Kill Process&lt;/strong&gt; to free up the file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;6. Run Visual Studio as Administrator&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Sometimes, Visual Studio or your IDE may not have sufficient permissions to access certain files, leading to this error. Running your IDE as an administrator can resolve permission-related issues.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Right-click on the &lt;strong&gt;Visual Studio&lt;/strong&gt; or &lt;strong&gt;VS Code&lt;/strong&gt; icon and select &lt;strong&gt;Run as administrator&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;After launching the IDE as an administrator, try rebuilding the project again.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;7. Disable Antivirus or Backup Software&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Antivirus programs or cloud backup services may scan or back up files while the build process is happening, causing the file to be locked. Temporarily disable your antivirus or backup software and try building the project again.&lt;/p&gt;

&lt;p&gt;Be sure to re-enable the software once you’ve completed the build.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;8. Reboot the System&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;If none of the above steps resolve the issue, a system reboot can help clear any lingering locks or processes holding onto the file.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Restart your computer to ensure that any file handles are released and the file is no longer in use.&lt;/li&gt;
&lt;li&gt;After rebooting, try building the project again.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The "file being used by another process" error is common when building or deploying .NET projects. It usually occurs when an executable file is locked by a process that is still running or using the file. By following the steps outlined above, you can quickly identify and resolve the issue.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Close any running applications&lt;/strong&gt; or processes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clean and rebuild the project&lt;/strong&gt; to remove any old files.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use tools like Process Explorer&lt;/strong&gt; to identify and kill processes that are locking the file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delete the bin and obj folders manually&lt;/strong&gt; to remove old assemblies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run your IDE as administrator&lt;/strong&gt; if necessary.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reboot your system&lt;/strong&gt; if other methods fail.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By systematically following these steps, you should be able to resolve the issue and proceed with your development process without further interruptions.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>dotnet</category>
      <category>dotnetcore</category>
      <category>azure</category>
    </item>
    <item>
      <title>Managing Relationships, Migrations, and Performance Optimization in ASP.NET Core MVC</title>
      <dc:creator>Sardar Mudassar Ali Khan</dc:creator>
      <pubDate>Sun, 05 Jan 2025 18:34:13 +0000</pubDate>
      <link>https://forem.com/sardarmudassaralikhan/managing-relationships-migrations-and-performance-optimization-in-aspnet-core-mvc-1pg</link>
      <guid>https://forem.com/sardarmudassaralikhan/managing-relationships-migrations-and-performance-optimization-in-aspnet-core-mvc-1pg</guid>
      <description>&lt;p&gt;Building scalable and efficient ASP.NET Core MVC applications requires careful attention to database relationships, migrations, and performance optimization. This article covers these aspects comprehensively, guiding you through best practices and implementation strategies.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Managing Relationships in ASP.NET Core MVC&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Entity Framework Core (EF Core) simplifies defining and managing relationships in your database. Understanding and implementing relationships effectively ensures data integrity and simplifies querying related data.&lt;/p&gt;

&lt;p&gt;a. One-to-One Relationship&lt;/p&gt;

&lt;p&gt;In a one-to-one relationship, one entity is associated with exactly one other entity.&lt;/p&gt;

&lt;p&gt;Entity Classes:&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 User
{
    public int Id { get; set; }
    public string Name { get; set; }
    public UserProfile Profile { get; set; }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class UserProfile
{
    public int Id { get; set; }
    public string Bio { get; set; }
    public int UserId { get; set; }
    public User User { get; set; }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configuration in DbContext:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity&amp;lt;User&amp;gt;()
        .HasOne(u =&amp;gt; u.Profile)
        .WithOne(p =&amp;gt; p.User)
        .HasForeignKey&amp;lt;UserProfile&amp;gt;(p =&amp;gt; p.UserId);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;b. One-to-Many Relationship&lt;/p&gt;

&lt;p&gt;In a one-to-many relationship, one entity is related to many others.&lt;/p&gt;

&lt;p&gt;Entity Classes:&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 Author
{
    public int Id { get; set; }
    public string Name { get; set; }
    public ICollection&amp;lt;Book&amp;gt; Books { get; set; }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Book
{
    public int Id { get; set; }
    public string Title { get; set; }
    public int AuthorId { get; set; }
    public Author Author { get; set; }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity&amp;lt;Author&amp;gt;()
        .HasMany(a =&amp;gt; a.Books)
        .WithOne(b =&amp;gt; b.Author)
        .HasForeignKey(b =&amp;gt; b.AuthorId);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;c. Many-to-Many Relationship&lt;/p&gt;

&lt;p&gt;EF Core 5.0+ supports many-to-many relationships without requiring a join entity.&lt;/p&gt;

&lt;p&gt;Entity Classes:&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 Student
{
    public int Id { get; set; }
    public string Name { get; set; }
    public ICollection&amp;lt;Course&amp;gt; Courses { get; set; }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Course
{
    public int Id { get; set; }
    public string Title { get; set; }
    public ICollection&amp;lt;Student&amp;gt; Students { get; set; }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;EF Core Automatically Creates a Join Table&lt;/p&gt;

&lt;p&gt;No additional configuration is required for basic many-to-many relationships.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Migrations in ASP.NET Core MVC&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Migrations are essential for evolving your database schema over time while maintaining data integrity.&lt;/p&gt;

&lt;p&gt;a. Creating and Applying Migrations&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Add a migration:

dotnet ef migrations add InitialCreate

Apply the migration:

dotnet ef database update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;b. Updating Migrations&lt;/p&gt;

&lt;p&gt;When you modify your entity models:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Add a new migration:

dotnet ef migrations add UpdateSchema

Apply the migration:

dotnet ef database update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;c. Rolling Back Migrations&lt;/p&gt;

&lt;p&gt;To revert to a previous migration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet ef database update PreviousMigrationName

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

&lt;/div&gt;



&lt;p&gt;d. Seeding Data&lt;/p&gt;

&lt;p&gt;Seed data in the OnModelCreating method to populate initial data.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity&amp;lt;Author&amp;gt;().HasData(
        new Author { Id = 1, Name = "John Doe" },
        new Author { Id = 2, Name = "Jane Smith" }
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the migrations to apply the seed data.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Performance Optimization&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Optimizing performance ensures scalability and a better user experience. Below are strategies for improving performance in ASP.NET Core MVC.&lt;/p&gt;

&lt;p&gt;a. Query Optimization&lt;/p&gt;

&lt;p&gt;Use AsNoTracking for read-only queries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var books = _context.Books.AsNoTracking().ToList();

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

&lt;/div&gt;



&lt;p&gt;Use Eager Loading to fetch related data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var author = _context.Authors.Include(a =&amp;gt; a.Books).FirstOrDefault(a =&amp;gt; a.Id == id);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;b. Indexing&lt;/p&gt;

&lt;p&gt;Define indexes on frequently queried columns to improve performance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity&amp;lt;Book&amp;gt;()
        .HasIndex(b =&amp;gt; b.Title)
        .HasDatabaseName("Index_Title");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;c. Caching&lt;/p&gt;

&lt;p&gt;Use caching to store frequently accessed data:&lt;/p&gt;

&lt;p&gt;MemoryCache:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services.AddMemoryCache();

if (!_cache.TryGetValue("Books", out List&amp;lt;Book&amp;gt; books))
{
    books = _context.Books.ToList();
    _cache.Set("Books", books, TimeSpan.FromMinutes(5));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;d. Pagination&lt;/p&gt;

&lt;p&gt;Fetch data in chunks using Skip and Take:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var books = _context.Books
    .Skip((pageNumber - 1) * pageSize)
    .Take(pageSize)
    .ToList();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;e. Database Connection Pooling&lt;/p&gt;

&lt;p&gt;Enable connection pooling in the connection string:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"ConnectionStrings": {
    "DefaultConnection": "Server=.;Database=MyDb;Trusted_Connection=True;Pooling=true;"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;f. Profiling Tools&lt;/p&gt;

&lt;p&gt;Use profiling tools like MiniProfiler to identify performance bottlenecks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet add package MiniProfiler.AspNetCore.Mvc

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Monitoring and Diagnostics&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Application Insights: Monitor application performance in production.&lt;/p&gt;

&lt;p&gt;Logging: Implement structured logging using libraries like Serilog or NLog.&lt;/p&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;Managing relationships, migrations, and optimizing performance in ASP.NET Core MVC is crucial for building scalable, maintainable, and efficient applications. By leveraging EF Core for relationships, employing robust migration strategies, and implementing performance best practices, developers can create applications that are both performant and easy to maintain.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>aspdotnet</category>
      <category>microsoft</category>
    </item>
    <item>
      <title>Azure Cosmos DB and its use with .NET</title>
      <dc:creator>Sardar Mudassar Ali Khan</dc:creator>
      <pubDate>Sun, 28 Jan 2024 20:03:09 +0000</pubDate>
      <link>https://forem.com/sardarmudassaralikhan/azure-cosmos-db-and-its-use-with-net-31hl</link>
      <guid>https://forem.com/sardarmudassaralikhan/azure-cosmos-db-and-its-use-with-net-31hl</guid>
      <description>&lt;p&gt;Azure Cosmos DB is a globally distributed, multi-model database service offered by Microsoft Azure. It's designed to provide high availability, scalability, and low-latency access to data for cloud-native applications. With its support for various data models, including document, key-value, graph, and column-family, Azure Cosmos DB is a versatile choice for a wide range of use cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Features of Azure Cosmos DB:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Global Distribution&lt;/strong&gt;: Azure Cosmos DB allows you to replicate data across multiple Azure regions globally, ensuring low-latency access for users worldwide.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Multi-model Support&lt;/strong&gt;: Whether your data is structured or unstructured, Azure Cosmos DB supports multiple data models, giving you the flexibility to choose the best model for your application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Elastic Scalability&lt;/strong&gt;: Azure Cosmos DB offers elastic scalability, allowing you to scale both throughput and storage independently based on your application's needs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enterprise-grade Security&lt;/strong&gt;: Azure Cosmos DB integrates seamlessly with Azure Active Directory for authentication and supports encryption at rest and in transit to ensure data security and compliance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Consistency Levels&lt;/strong&gt;: You can choose from a range of consistency levels, including strong, bounded staleness, session, or eventual consistency, depending on your application's requirements.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Integration with .NET:
&lt;/h2&gt;

&lt;p&gt;Azure Cosmos DB provides a .NET SDK that simplifies the process of integrating Cosmos DB with .NET applications. Here's how you can get started with Azure Cosmos DB in a .NET application:&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Install the Azure Cosmos DB SDK
&lt;/h3&gt;

&lt;p&gt;You can install the Azure Cosmos DB SDK via NuGet Package Manager or .NET CLI using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet add package Microsoft.Azure.Cosmos
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Create a CosmosClient Instance
&lt;/h3&gt;

&lt;p&gt;Initialize a &lt;code&gt;CosmosClient&lt;/code&gt; instance with your Cosmos DB account's connection string:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Microsoft.Azure.Cosmos&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;CosmosClient&lt;/span&gt; &lt;span class="n"&gt;cosmosClient&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;CosmosClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"your_connection_string"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Work with Databases and Containers
&lt;/h3&gt;

&lt;p&gt;Use the &lt;code&gt;Database&lt;/code&gt; and &lt;code&gt;Container&lt;/code&gt; classes to interact with databases and containers in Cosmos DB:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Database&lt;/span&gt; &lt;span class="n"&gt;database&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;cosmosClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateDatabaseIfNotExistsAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"YourDatabaseId"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;Container&lt;/span&gt; &lt;span class="n"&gt;container&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateContainerIfNotExistsAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"YourContainerId"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"/PartitionKey"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Perform CRUD Operations
&lt;/h3&gt;

&lt;p&gt;Use the &lt;code&gt;Item&lt;/code&gt; and &lt;code&gt;Container&lt;/code&gt; classes to perform CRUD operations on documents within containers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;YourItem&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;YourItem&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"John"&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="n"&gt;ItemResponse&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;YourItem&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CreateItemAsync&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;YourItem&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5: Query Data
&lt;/h3&gt;

&lt;p&gt;Execute SQL queries against Cosmos DB using the &lt;code&gt;Container&lt;/code&gt; class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;QueryDefinition&lt;/span&gt; &lt;span class="n"&gt;queryDefinition&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;QueryDefinition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"SELECT * FROM c WHERE c.Name = @name"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WithParameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"@name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"John"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;FeedIterator&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;YourItem&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;queryResultSetIterator&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetItemQueryIterator&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;YourItem&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;queryDefinition&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;queryResultSetIterator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HasMoreResults&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;FeedResponse&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;YourItem&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;currentResultSet&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;queryResultSetIterator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ReadNextAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;YourItem&lt;/span&gt; &lt;span class="n"&gt;currentItem&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;currentResultSet&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;currentItem&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 6: Handle Throughput and Performance
&lt;/h3&gt;

&lt;p&gt;Azure Cosmos DB allows you to configure throughput settings based on your application's needs to ensure optimal performance and cost-efficiency.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;Azure Cosmos DB, combined with its seamless integration with .NET, empowers developers to build highly scalable and globally distributed applications with ease. By leveraging the Azure Cosmos DB SDK for .NET, developers can take advantage of its rich features and APIs to create robust and efficient cloud-native solutions that meet the demands of modern applications.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Exploring the Enhancements in ASP.NET Core 8.0</title>
      <dc:creator>Sardar Mudassar Ali Khan</dc:creator>
      <pubDate>Sat, 27 Jan 2024 23:52:47 +0000</pubDate>
      <link>https://forem.com/sardarmudassaralikhan/exploring-the-enhancements-in-aspnet-core-80-58fn</link>
      <guid>https://forem.com/sardarmudassaralikhan/exploring-the-enhancements-in-aspnet-core-80-58fn</guid>
      <description>&lt;p&gt;In the ever-evolving landscape of web development, staying abreast of the latest advancements is paramount to ensuring optimal performance, security, and scalability for web applications. &lt;strong&gt;ASP.NET Core 8.0&lt;/strong&gt; emerges as a pivotal milestone in the ASP.NET Core framework, introducing a plethora of enhancements and features that redefine the development experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Evolution of ASP.NET Core
&lt;/h2&gt;

&lt;p&gt;ASP.NET Core has undergone a remarkable evolution since its inception, marked by a commitment to open-source collaboration, cross-platform compatibility, and robust performance. With each iteration, the framework has strived to empower developers with cutting-edge tools and technologies, fostering innovation and efficiency in web application development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Unveiling ASP.NET Core 8.0
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Performance Optimization
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;ASP.NET Core 8.0&lt;/strong&gt; places a premium on performance optimization, leveraging advanced techniques to enhance the speed and responsiveness of web applications. Through streamlined processing pipelines, efficient resource utilization, and optimized caching mechanisms, &lt;strong&gt;ASP.NET Core 8.0&lt;/strong&gt; delivers unparalleled performance gains, ensuring seamless user experiences across diverse platforms and devices.&lt;/p&gt;

&lt;h3&gt;
  
  
  Enhanced Security Features
&lt;/h3&gt;

&lt;p&gt;Security remains a paramount concern in modern web development, and &lt;strong&gt;ASP.NET Core 8.0&lt;/strong&gt; reaffirms its commitment to robust security practices. With enhanced encryption algorithms, comprehensive authentication mechanisms, and proactive threat detection capabilities, &lt;strong&gt;ASP.NET Core 8.0&lt;/strong&gt; empowers developers to fortify their web applications against evolving cybersecurity threats, safeguarding sensitive data and preserving user trust.&lt;/p&gt;

&lt;h3&gt;
  
  
  Improved Developer Productivity
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;ASP.NET Core 8.0&lt;/strong&gt; prioritizes developer productivity, offering an array of features and tools designed to streamline the development process. From integrated development environments (IDEs) with intuitive interfaces to &lt;strong&gt;built-in&lt;/strong&gt; templates and scaffolding tools, &lt;strong&gt;ASP.NET Core 8.0&lt;/strong&gt; accelerates &lt;strong&gt;the&lt;/strong&gt; creation of robust, feature-rich web applications, empowering developers to focus on innovation and creativity.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cross-Platform Compatibility
&lt;/h3&gt;

&lt;p&gt;In an era of diverse operating systems and devices, cross-platform compatibility is imperative for reaching a broad audience. &lt;strong&gt;ASP.NET Core 8.0&lt;/strong&gt; embraces this ethos, providing seamless support for various platforms, including Windows, Linux, and macOS. By leveraging &lt;strong&gt;the&lt;/strong&gt; .NET &lt;strong&gt;5&lt;/strong&gt; framework, &lt;strong&gt;ASP.NET Core 8.0&lt;/strong&gt; enables developers to deploy &lt;strong&gt;web&lt;/strong&gt; applications &lt;strong&gt;across&lt;/strong&gt; multiple platforms with ease, facilitating &lt;strong&gt;a&lt;/strong&gt; ubiquitous &lt;strong&gt;user&lt;/strong&gt; experience &lt;strong&gt;across&lt;/strong&gt; diverse environments.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advanced Containerization Support
&lt;/h3&gt;

&lt;p&gt;Containerization has emerged as a &lt;strong&gt;pivotal&lt;/strong&gt; paradigm in modern &lt;strong&gt;application&lt;/strong&gt; deployment, enabling &lt;strong&gt;the&lt;/strong&gt; efficient &lt;strong&gt;packaging&lt;/strong&gt; and &lt;strong&gt;deployment&lt;/strong&gt; of &lt;strong&gt;web&lt;/strong&gt; applications &lt;strong&gt;across&lt;/strong&gt; diverse &lt;strong&gt;environments&lt;/strong&gt;. &lt;strong&gt;ASP.NET Core 8.0&lt;/strong&gt; embraces &lt;strong&gt;this&lt;/strong&gt; trend &lt;strong&gt;with&lt;/strong&gt; advanced &lt;strong&gt;containerization&lt;/strong&gt; support, facilitating &lt;strong&gt;the&lt;/strong&gt; seamless integration &lt;strong&gt;of&lt;/strong&gt; &lt;strong&gt;ASP.NET&lt;/strong&gt; &lt;strong&gt;Core&lt;/strong&gt; &lt;strong&gt;applications&lt;/strong&gt; &lt;strong&gt;with&lt;/strong&gt; container orchestration platforms &lt;strong&gt;such&lt;/strong&gt; &lt;strong&gt;as&lt;/strong&gt; &lt;strong&gt;Docker&lt;/strong&gt; &lt;strong&gt;and&lt;/strong&gt; Kubernetes. &lt;strong&gt;By&lt;/strong&gt; &lt;strong&gt;providing&lt;/strong&gt; &lt;strong&gt;native&lt;/strong&gt; &lt;strong&gt;support&lt;/strong&gt; &lt;strong&gt;for&lt;/strong&gt; &lt;strong&gt;containerization&lt;/strong&gt;, &lt;strong&gt;ASP.NET&lt;/strong&gt; &lt;strong&gt;Core&lt;/strong&gt; &lt;strong&gt;8.0&lt;/strong&gt; &lt;strong&gt;empowers&lt;/strong&gt; developers &lt;strong&gt;to&lt;/strong&gt; &lt;strong&gt;leverage&lt;/strong&gt; &lt;strong&gt;the&lt;/strong&gt; scalability, &lt;strong&gt;portability&lt;/strong&gt;, and &lt;strong&gt;efficiency&lt;/strong&gt; &lt;strong&gt;of&lt;/strong&gt; &lt;strong&gt;container&lt;/strong&gt; &lt;strong&gt;technologies&lt;/strong&gt; &lt;strong&gt;in&lt;/strong&gt; &lt;strong&gt;their&lt;/strong&gt; &lt;strong&gt;web&lt;/strong&gt; &lt;strong&gt;applications&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;ASP.NET Core 8.0&lt;/strong&gt; represents a paradigm shift in web development, &lt;strong&gt;ushering&lt;/strong&gt; &lt;strong&gt;in&lt;/strong&gt; &lt;strong&gt;a&lt;/strong&gt; new era &lt;strong&gt;of&lt;/strong&gt; &lt;strong&gt;innovation&lt;/strong&gt;, efficiency, and &lt;strong&gt;scalability&lt;/strong&gt;. &lt;strong&gt;With&lt;/strong&gt; its &lt;strong&gt;emphasis&lt;/strong&gt; &lt;strong&gt;on&lt;/strong&gt; &lt;strong&gt;performance&lt;/strong&gt;, &lt;strong&gt;security&lt;/strong&gt;, &lt;strong&gt;developer&lt;/strong&gt; &lt;strong&gt;productivity&lt;/strong&gt;, &lt;strong&gt;cross-platform&lt;/strong&gt; &lt;strong&gt;compatibility&lt;/strong&gt;, and &lt;strong&gt;containerization&lt;/strong&gt; &lt;strong&gt;support&lt;/strong&gt;, &lt;strong&gt;ASP.NET&lt;/strong&gt; &lt;strong&gt;Core&lt;/strong&gt; &lt;strong&gt;8.0&lt;/strong&gt; &lt;strong&gt;empowers&lt;/strong&gt; &lt;strong&gt;developers&lt;/strong&gt; &lt;strong&gt;to&lt;/strong&gt; &lt;strong&gt;build&lt;/strong&gt; &lt;strong&gt;next-generation&lt;/strong&gt; &lt;strong&gt;web&lt;/strong&gt; &lt;strong&gt;applications&lt;/strong&gt; &lt;strong&gt;that&lt;/strong&gt; &lt;strong&gt;exceed&lt;/strong&gt; &lt;strong&gt;expectations&lt;/strong&gt;. &lt;strong&gt;By&lt;/strong&gt; &lt;strong&gt;leveraging&lt;/strong&gt; &lt;strong&gt;the&lt;/strong&gt; &lt;strong&gt;latest&lt;/strong&gt; &lt;strong&gt;technologies&lt;/strong&gt; &lt;strong&gt;and&lt;/strong&gt; &lt;strong&gt;best&lt;/strong&gt; &lt;strong&gt;practices&lt;/strong&gt;, &lt;strong&gt;ASP.NET&lt;/strong&gt; &lt;strong&gt;Core&lt;/strong&gt; &lt;strong&gt;8.0&lt;/strong&gt; &lt;strong&gt;paves&lt;/strong&gt; &lt;strong&gt;the&lt;/strong&gt; &lt;strong&gt;way&lt;/strong&gt; &lt;strong&gt;for&lt;/strong&gt; &lt;strong&gt;a&lt;/strong&gt; &lt;strong&gt;brighter&lt;/strong&gt;, &lt;strong&gt;more&lt;/strong&gt; &lt;strong&gt;innovative&lt;/strong&gt; &lt;strong&gt;future&lt;/strong&gt; &lt;strong&gt;in&lt;/strong&gt; &lt;strong&gt;web&lt;/strong&gt; &lt;strong&gt;development&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Understanding Goal-Based Software Engineering A Path to Successful Software Development</title>
      <dc:creator>Sardar Mudassar Ali Khan</dc:creator>
      <pubDate>Fri, 26 Jan 2024 20:16:56 +0000</pubDate>
      <link>https://forem.com/sardarmudassaralikhan/understanding-goal-based-software-engineering-a-path-to-successful-software-development-12al</link>
      <guid>https://forem.com/sardarmudassaralikhan/understanding-goal-based-software-engineering-a-path-to-successful-software-development-12al</guid>
      <description>&lt;h1&gt;
  
  
  &lt;strong&gt;Goal-Based Software Engineering&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Software development is becoming increasingly complex. With the growing demands for sophisticated and user-centric applications, traditional approaches to software engineering are no longer sufficient. This has led to the emergence of goal-based software engineering, a paradigm that focuses on aligning software development efforts with specific objectives and user needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Process of Goal-Based Software Engineering
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Understanding User Needs and Requirements
&lt;/h3&gt;

&lt;p&gt;Before embarking on any software development project, it is crucial to gain a deep understanding of the users' needs and requirements. This involves conducting thorough research, engaging with stakeholders, and gathering feedback to identify the goals that the software should achieve.&lt;/p&gt;

&lt;h3&gt;
  
  
  Establishing Clear and Achievable Goals
&lt;/h3&gt;

&lt;p&gt;Once the user needs have been identified, the next step is to establish clear and achievable goals for the software. These goals should be specific, measurable, attainable, relevant, and time-bound (SMART), providing a clear direction for the development process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Designing Solutions to Meet the Goals
&lt;/h3&gt;

&lt;p&gt;With the goals in place, the software design phase focuses on developing solutions that effectively address these objectives. This involves creating a detailed plan outlining the features, functionalities, and architecture required to meet the established goals.&lt;/p&gt;

&lt;h3&gt;
  
  
  Implementing and Testing the Software
&lt;/h3&gt;

&lt;p&gt;Once the design is finalized, the software development team begins the implementation phase, translating the design into a functioning product. Throughout this process, rigorous testing is conducted to ensure that the software meets the predefined goals and performs as expected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Principles of Goal-Based Software Engineering
&lt;/h2&gt;

&lt;p&gt;Goal-based software engineering is guided by several key principles that help ensure the successful alignment of software development efforts with user objectives:&lt;/p&gt;

&lt;h3&gt;
  
  
  Goal Decomposition
&lt;/h3&gt;

&lt;p&gt;Goal decomposition involves breaking down high-level goals into smaller, more manageable sub-goals. This hierarchical approach allows for better organization and prioritization of tasks, facilitating more efficient software development.&lt;/p&gt;

&lt;h3&gt;
  
  
  Goal Refinement
&lt;/h3&gt;

&lt;p&gt;Goal refinement involves refining the initial goals based on feedback and changing requirements. This iterative process ensures that the software remains aligned with user needs and evolving business objectives throughout the development lifecycle.&lt;/p&gt;

&lt;h3&gt;
  
  
  Goal Satisfaction
&lt;/h3&gt;

&lt;p&gt;The ultimate aim of goal-based software engineering is to achieve goal satisfaction, ensuring that the software effectively fulfills the predefined objectives and delivers value to the end-users.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of Goal-Based Software Engineering
&lt;/h2&gt;

&lt;p&gt;Goal-based software engineering offers several advantages over traditional development approaches:&lt;/p&gt;

&lt;h3&gt;
  
  
  Enhanced Focus on User Requirements
&lt;/h3&gt;

&lt;p&gt;By prioritizing user goals and objectives, goal-based software engineering ensures that the resulting software meets the specific needs of its intended users, leading to higher user satisfaction and adoption rates.&lt;/p&gt;

&lt;h3&gt;
  
  
  Improved Software Quality
&lt;/h3&gt;

&lt;p&gt;By aligning development efforts with clear and measurable goals, goal-based software engineering helps maintain a focus on quality throughout the development process, resulting in more robust and reliable software.&lt;/p&gt;

&lt;h3&gt;
  
  
  Flexibility in Adapting to Changing Needs
&lt;/h3&gt;

&lt;p&gt;The iterative nature of goal-based development allows for greater flexibility in adapting to changing user requirements and market conditions, ensuring that the software remains relevant and competitive over time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges and Limitations
&lt;/h2&gt;

&lt;p&gt;Despite its benefits, goal-based software engineering also poses several challenges and limitations:&lt;/p&gt;

&lt;h3&gt;
  
  
  Complexity in Defining Goals
&lt;/h3&gt;

&lt;p&gt;Defining clear and achievable goals can be challenging, especially in complex software projects with multiple stakeholders and conflicting objectives. Effective communication and collaboration are essential to ensure that all parties are aligned on the project goals.&lt;/p&gt;

&lt;h3&gt;
  
  
  Balancing Conflicting Goals
&lt;/h3&gt;

&lt;p&gt;In some cases, different stakeholders may have conflicting goals or priorities, requiring careful negotiation and compromise to find a mutually acceptable solution. This can introduce additional complexity and delays into the development process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ensuring Alignment with Business Objectives
&lt;/h3&gt;

&lt;p&gt;To be successful, goal-based software engineering must align closely with the broader strategic objectives of the organization. This requires strong leadership and effective communication to ensure that the software development efforts support the overall business goals.&lt;/p&gt;

&lt;h2&gt;
  
  
  Case Studies
&lt;/h2&gt;

&lt;p&gt;Several real-world examples illustrate the effectiveness of goal-based software engineering in practice:&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 1: E-commerce Platform
&lt;/h3&gt;

&lt;p&gt;A leading e-commerce platform implemented goal-based software engineering to enhance its recommendation engine. By aligning development efforts with user goals, such as personalized product recommendations and seamless checkout experiences, the platform saw a significant increase in user engagement and sales.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 2: Healthcare Application
&lt;/h3&gt;

&lt;p&gt;A healthcare application utilized goal-based software engineering to improve patient outcomes. By focusing on goals such as accurate diagnosis, timely treatment, and patient satisfaction, the application was able to streamline clinical workflows and deliver better healthcare services to patients.&lt;/p&gt;

&lt;h2&gt;
  
  
  Future Trends and Innovations
&lt;/h2&gt;

&lt;p&gt;Looking ahead, several trends and innovations are shaping the future of goal-based software engineering:&lt;/p&gt;

&lt;h3&gt;
  
  
  Advances in Goal Modeling Techniques
&lt;/h3&gt;

&lt;p&gt;Recent advances in goal modeling techniques, such as the use of formal methods and artificial intelligence, are enabling more accurate and efficient goal specification and refinement.&lt;/p&gt;

&lt;h3&gt;
  
  
  Integration of Artificial Intelligence
&lt;/h3&gt;

&lt;p&gt;The integration of artificial intelligence and machine learning technologies into goal-based software engineering is opening up new possibilities for automated goal generation, optimization, and adaptation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Emerging Methodologies in Goal-Based Development
&lt;/h3&gt;

&lt;p&gt;New methodologies, such as Goal-Oriented Requirements Engineering (GORE) and Goal-Driven Development (GDD), are emerging to provide structured approaches for goal-based software engineering, helping organizations effectively manage and prioritize their development efforts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, goal-based software engineering offers a promising approach to software development that prioritizes user needs and objectives. By aligning development efforts with clear and achievable goals, organizations can build software that delivers value to end-users and drives business success.&lt;/p&gt;




&lt;h3&gt;
  
  
  Unique FAQs
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What are the key differences between goal-based software engineering and traditional development approaches?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Goal-based software engineering focuses on aligning development efforts with specific user goals and objectives, whereas traditional approaches may prioritize technical requirements or project constraints.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;How does goal decomposition help in the software development process?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Goal decomposition involves breaking down high-level goals into smaller, more manageable sub-goals, which helps organize and prioritize tasks, leading to more efficient development.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What role does goal refinement play in goal-based software engineering?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Goal refinement involves iterating on the initial goals based on feedback and changing requirements, ensuring that the software remains aligned with user needs and evolving business objectives throughout the development lifecycle.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How can organizations overcome the challenges of conflicting goals in goal-based software engineering?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Organizations can overcome conflicting goals by fostering effective communication and collaboration among stakeholders, facilitating negotiation and compromise to find mutually acceptable solutions.&lt;/p&gt;

&lt;p&gt;What are some future trends in goal-based software engineering?&lt;/p&gt;

&lt;p&gt;Future trends in goal-based software engineering include advances in goal modeling techniques, integration of artificial intelligence, and the emergence of new methodologies to provide structured approaches for goal-driven development.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>softwareengineering</category>
      <category>sre</category>
    </item>
    <item>
      <title>Harnessing Azure Cosmos DB with .NET: A Developer's Guide</title>
      <dc:creator>Sardar Mudassar Ali Khan</dc:creator>
      <pubDate>Fri, 26 Jan 2024 10:29:58 +0000</pubDate>
      <link>https://forem.com/sardarmudassaralikhan/harnessing-azure-cosmos-db-with-net-a-developers-guide-k25</link>
      <guid>https://forem.com/sardarmudassaralikhan/harnessing-azure-cosmos-db-with-net-a-developers-guide-k25</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;Azure Cosmos DB is a globally distributed, multi-model database service provided by Microsoft Azure. It offers unparalleled scalability, performance, and flexibility for building modern, cloud-native applications. In this article, we'll explore how Azure Cosmos DB seamlessly integrates with .NET, empowering developers to leverage its capabilities to their fullest extent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Overview of Azure Cosmos DB:
&lt;/h2&gt;

&lt;p&gt;Azure Cosmos DB is a fully managed NoSQL database service designed to handle globally distributed, high-throughput applications with ease. It supports multiple data models including document, key-value, graph, and column-family, providing developers with the flexibility to choose the right data model for their application needs.&lt;/p&gt;

&lt;p&gt;Key Features of Azure Cosmos DB:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Global Distribution&lt;/strong&gt;: Azure Cosmos DB offers global distribution with turnkey multi-region replication, enabling low-latency access to data from any region around the world.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Elastic Scalability&lt;/strong&gt;: With Azure Cosmos DB, developers can scale throughput and storage independently based on application demand, ensuring optimal performance and cost-effectiveness.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Multi-model Support&lt;/strong&gt;: Azure Cosmos DB supports multiple data models including document, key-value, graph, and column-family, allowing developers to use the most appropriate model for their data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Consistency Levels&lt;/strong&gt;: Azure Cosmos DB offers configurable consistency levels, allowing developers to choose between strong, bounded staleness, session, or eventual consistency based on their application requirements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enterprise-grade Security&lt;/strong&gt;: Azure Cosmos DB integrates with Azure Active Directory for seamless authentication and supports encryption at rest and in transit to ensure data security.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;.NET Integration with Azure Cosmos DB:&lt;/p&gt;

&lt;p&gt;Integrating Azure Cosmos DB with .NET applications is straightforward, thanks to the Azure Cosmos DB .NET SDK provided by Microsoft. This SDK abstracts the complexity of interacting with Azure Cosmos DB and provides a rich set of APIs for CRUD operations, query execution, and more.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Install the Azure Cosmos DB .NET SDK
&lt;/h3&gt;

&lt;p&gt;In your .NET application, install the Azure Cosmos DB .NET SDK using the following NuGet package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet add package Microsoft.Azure.Cosmos
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Connect to Azure Cosmos DB
&lt;/h3&gt;

&lt;p&gt;Create an instance of the &lt;code&gt;CosmosClient&lt;/code&gt; class by passing the connection string and database name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Microsoft.Azure.Cosmos&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;CosmosClient&lt;/span&gt; &lt;span class="n"&gt;cosmosClient&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;CosmosClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"connectionString"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Create or Retrieve Databases and Containers
&lt;/h3&gt;

&lt;p&gt;Use the &lt;code&gt;Database&lt;/code&gt; and &lt;code&gt;Container&lt;/code&gt; classes to create or retrieve databases and containers within Azure Cosmos DB:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Database&lt;/span&gt; &lt;span class="n"&gt;database&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;cosmosClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateDatabaseIfNotExistsAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"DatabaseName"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;Container&lt;/span&gt; &lt;span class="n"&gt;container&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateContainerIfNotExistsAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"ContainerName"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"/PartitionKey"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Perform CRUD Operations
&lt;/h3&gt;

&lt;p&gt;Use the &lt;code&gt;Container&lt;/code&gt; class to perform CRUD operations on documents within containers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Create a document&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Guid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;NewGuid&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"John Doe"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;30&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateItemAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Read a document&lt;/span&gt;
&lt;span class="n"&gt;ItemResponse&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;dynamic&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ReadItemAsync&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;dynamic&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;PartitionKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// Update a document&lt;/span&gt;
&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;31&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ReplaceItemAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;PartitionKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// Delete a document&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DeleteItemAsync&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;dynamic&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;PartitionKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5: Query Data
&lt;/h3&gt;

&lt;p&gt;Execute SQL queries against Azure Cosmos DB using the &lt;code&gt;Container&lt;/code&gt; class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"SELECT * FROM c WHERE c.age &amp;gt; @age"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;parameters&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SqlParameterCollection&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SqlParameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"@age"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;25&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="n"&gt;QueryDefinition&lt;/span&gt; &lt;span class="n"&gt;queryDefinition&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;QueryDefinition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;WithParameters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;FeedIterator&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;dynamic&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;resultSetIterator&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetItemQueryIterator&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;dynamic&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;queryDefinition&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resultSetIterator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HasMoreResults&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;FeedResponse&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;dynamic&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;resultSetIterator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ReadNextAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 6: Handle Throughput and Performance
&lt;/h3&gt;

&lt;p&gt;Azure Cosmos DB offers provisioned throughput and autoscale options for handling throughput requirements. Adjust throughput settings based on your application's needs to ensure optimal performance and cost-efficiency.&lt;/p&gt;

&lt;p&gt;Conclusion:&lt;/p&gt;

&lt;p&gt;Azure Cosmos DB, coupled with .NET integration, empowers developers to build highly scalable and globally distributed applications with ease. The Azure Cosmos DB .NET SDK simplifies interactions with Azure Cosmos DB, providing a rich set of APIs for CRUD operations, querying, and performance optimization. By leveraging Azure Cosmos DB in .NET applications, developers can unlock the full potential of modern, cloud-native architectures, delivering robust and scalable solutions to meet the demands of today's data-intensive applications.&lt;/p&gt;

</description>
      <category>azure</category>
      <category>azurefunctions</category>
      <category>azurecosmosdatabase</category>
      <category>programming</category>
    </item>
    <item>
      <title>Harnessing the Cloud: Azure Blob Storage and Seamless .NET Integration</title>
      <dc:creator>Sardar Mudassar Ali Khan</dc:creator>
      <pubDate>Wed, 24 Jan 2024 14:39:56 +0000</pubDate>
      <link>https://forem.com/sardarmudassaralikhan/harnessing-the-cloud-azure-blob-storage-and-seamless-net-integration-5384</link>
      <guid>https://forem.com/sardarmudassaralikhan/harnessing-the-cloud-azure-blob-storage-and-seamless-net-integration-5384</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;In the era of cloud computing, data storage is a critical aspect of modern application development. Azure Blob Storage, part of Microsoft's Azure Cloud platform, provides a scalable and cost-effective solution for storing and managing unstructured data. This article explores the seamless integration of Azure Blob Storage with .NET, empowering developers to build robust, scalable, and versatile applications with ease.&lt;/p&gt;

&lt;h2&gt;
  
  
  Azure Blob Storage Overview:
&lt;/h2&gt;

&lt;p&gt;Azure Blob Storage is a cloud-based object storage solution designed for the storage of large amounts of unstructured data, such as images, documents, videos, and backups. It is part of Azure Storage, a comprehensive suite that includes various storage services to cater to different data storage needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Features of Azure Blob Storage:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability&lt;/strong&gt;: Azure Blob Storage allows developers to scale their storage needs seamlessly. Whether it's a small application or a large-scale enterprise solution, Azure Blob Storage scales to meet the demands of the application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Durability and Redundancy&lt;/strong&gt;: Azure Blob Storage ensures high durability by replicating data across multiple data centers within a region. Redundancy options like Locally Redundant Storage (LRS), Zone-Redundant Storage (ZRS), and Geo-Redundant Storage (GRS) provide additional layers of data protection.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security&lt;/strong&gt;: Azure Blob Storage integrates with Azure Active Directory for identity and access management. Additionally, it supports Shared Access Signatures (SAS) for fine-grained control over data access.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Blob Tiers&lt;/strong&gt;: Azure Blob Storage offers different storage tiers to optimize costs based on the access patterns of the data. These include Hot, Cool, and Archive tiers, each with varying costs and access times.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Blob Indexer&lt;/strong&gt;: The Azure Blob Storage Indexer allows efficient and scalable full-text search over blobs using Azure Cognitive Search, enabling powerful data discovery.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  .NET Integration with Azure Blob Storage:
&lt;/h2&gt;

&lt;p&gt;Integrating Azure Blob Storage with .NET applications is straightforward, thanks to the Azure.Storage.Blobs NuGet package provided by Microsoft. This package simplifies the process of interacting with Azure Blob Storage.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Install the Azure.Storage.Blobs Package
&lt;/h3&gt;

&lt;p&gt;In your .NET application, install the Azure.Storage.Blobs package using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet add package Azure.Storage.Blobs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Connect to Azure Blob Storage
&lt;/h3&gt;

&lt;p&gt;Create a class to encapsulate the Azure Blob Storage operations. Initialize a &lt;code&gt;BlobServiceClient&lt;/code&gt; with the connection string of your Azure Storage account.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Azure.Storage.Blobs&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BlobStorageService&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;BlobServiceClient&lt;/span&gt; &lt;span class="n"&gt;_blobServiceClient&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;BlobStorageService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;connectionString&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_blobServiceClient&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;BlobServiceClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;connectionString&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Upload and Download Blobs
&lt;/h3&gt;

&lt;p&gt;Implement methods to upload and download blobs from Azure Blob Storage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;UploadBlobAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;containerName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;blobName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Stream&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;containerClient&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_blobServiceClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetBlobContainerClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;containerName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;blobClient&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;containerClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetBlobClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blobName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;blobClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;UploadAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Stream&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;DownloadBlobAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;containerName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;blobName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;containerClient&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_blobServiceClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetBlobContainerClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;containerName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;blobClient&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;containerClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetBlobClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blobName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;blobClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;OpenReadAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Content&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Integrate with .NET Applications
&lt;/h3&gt;

&lt;p&gt;Now, integrate the &lt;code&gt;BlobStorageService&lt;/code&gt; into your .NET application. For example, in an ASP.NET Core controller:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;ApiController&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"api/[controller]"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BlobController&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ControllerBase&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;BlobStorageService&lt;/span&gt; &lt;span class="n"&gt;_blobStorageService&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;BlobController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IConfiguration&lt;/span&gt; &lt;span class="n"&gt;configuration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;connectionString&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;configuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetConnectionString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"AzureBlobStorage"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;_blobStorageService&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;BlobStorageService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;connectionString&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;HttpPost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"upload"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IActionResult&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;UploadBlob&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;FromForm&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;IFormFile&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="p"&gt;||&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;BadRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Invalid file"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;stream&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;OpenReadStream&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_blobStorageService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;UploadBlobAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"containerName"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FileName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Blob uploaded successfully"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;HttpGet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"download/{blobName}"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IActionResult&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;DownloadBlob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;blobName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;stream&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_blobStorageService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;DownloadBlobAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"containerName"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;blobName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;NotFound&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Blob not found"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;File&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"application/octet-stream"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;blobName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5: Test the Integration
&lt;/h3&gt;

&lt;p&gt;Run your .NET application and use tools like Postman or curl to test the Blob Storage operations. Upload and download blobs to and from Azure Blob Storage seamlessly.&lt;/p&gt;

&lt;p&gt;Best Practices for .NET and Azure Blob Storage Integration:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Shared Access Signatures (SAS)&lt;/strong&gt;: Implement SAS for secure and time-limited access to blobs, reducing the need for exposing storage account keys.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Optimize Blob Storage Tiers&lt;/strong&gt;: Choose the appropriate blob storage tier based on the access patterns of your data to optimize costs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implement Retry Policies&lt;/strong&gt;: Implement retry policies to handle transient errors when interacting with Azure Blob Storage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor and Log Storage Operations&lt;/strong&gt;: Utilize Azure Monitoring and Azure Storage Analytics to monitor storage operations and log relevant information for troubleshooting.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Leverage Azure Blob Indexer&lt;/strong&gt;: Utilize the Azure Blob Storage Indexer for efficient full-text search capabilities over your blob data.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;Azure Blob Storage, coupled with .NET integration, empowers developers to build scalable and resilient applications with seamless access to unstructured data. The Azure.Storage.The Blobs package simplifies interactions, making it easy to incorporate Blob Storage into your .NET projects. By following best practices, developers can optimize costs, enhance security, and ensure the efficient management of unstructured data in the cloud. As the demand for scalable and versatile storage solutions continues to grow, Azure Blob Storage remains a cornerstone for modern .NET applications.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Azure SQL Database and Seamless .NET Integration</title>
      <dc:creator>Sardar Mudassar Ali Khan</dc:creator>
      <pubDate>Mon, 15 Jan 2024 11:52:55 +0000</pubDate>
      <link>https://forem.com/sardarmudassaralikhan/azure-sql-database-and-seamless-net-integration-2jn0</link>
      <guid>https://forem.com/sardarmudassaralikhan/azure-sql-database-and-seamless-net-integration-2jn0</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;In the dynamic landscape of cloud computing, Microsoft Azure stands out as a comprehensive platform offering a myriad of services. One such powerhouse service is the Azure SQL Database, a fully managed relational database service that provides a robust, scalable, and secure solution for data storage and management. This article delves into the seamless integration of Azure SQL Database with .NET, exploring the synergies that empower developers to build robust and scalable applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Azure SQL Database Overview:
&lt;/h2&gt;

&lt;p&gt;Azure SQL Database is a cloud-based relational database service built on the Microsoft SQL Server engine. It eliminates the complexities of traditional database management by handling tasks such as patching, backups, and monitoring automatically. With Azure SQL Database, developers can focus on building applications without worrying about the underlying infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Features of Azure SQL Database:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability&lt;/strong&gt;: Azure SQL Database allows developers to scale resources dynamically based on application demands. It supports both horizontal and vertical scaling, ensuring optimal performance during peak usage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security&lt;/strong&gt;: Security is a top priority in Azure SQL Database. It provides features such as Transparent Data Encryption (TDE), Dynamic Data Masking, and Always Encrypted to safeguard sensitive data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;High Availability&lt;/strong&gt;: Azure SQL Database ensures high availability through features like automatic backups, geo-replication, and failover groups. This guarantees business continuity and minimizes downtime.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Intelligent Performance&lt;/strong&gt;: With built-in intelligence, Azure SQL Database can adapt to workload patterns, optimizing performance through features like automatic tuning and query performance insights.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;.NET Integration with Azure SQL Database:&lt;/p&gt;

&lt;p&gt;Integrating .NET applications with Azure SQL Database is a straightforward process, thanks to robust tooling and libraries provided by Microsoft. Here are the key components of this integration:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ADO.NET Library&lt;/strong&gt;: Azure SQL Database seamlessly integrates with ADO.NET, a data access library for .NET applications. Developers can use ADO.NET to establish connections, execute queries, and manage data with ease.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Entity Framework (EF)&lt;/strong&gt;: Entity Framework, a popular Object-Relational Mapping (ORM) framework for .NET, simplifies data access in applications. Azure SQL Database supports EF, enabling developers to work with data using a more abstract, object-oriented approach.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SQL Server Management Studio (SSMS)&lt;/strong&gt;: SSMS provides a familiar environment for developers to interact with and manage Azure SQL Database. It facilitates tasks such as querying, designing schemas, and monitoring database performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Azure Data Studio&lt;/strong&gt;: This cross-platform database tool enhances the development and management experience. Azure Data Studio allows developers to write T-SQL queries, manage schema, and visualize data in a collaborative environment.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Best Practices for .NET and Azure SQL Database Integration:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Connection Pooling&lt;/strong&gt;: Utilize connection pooling to efficiently manage database connections, reducing the overhead of establishing and tearing down connections for each request.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Parameterized Queries&lt;/strong&gt;: Always use parameterized queries to prevent SQL injection attacks and improve query performance. Parameterized queries ensure that user inputs are treated as parameters rather than dynamic SQL statements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Asynchronous Programming&lt;/strong&gt;: Leverage asynchronous programming patterns, such as asynchronous methods and the &lt;code&gt;async/await&lt;/code&gt; keywords, to enhance application responsiveness when interacting with Azure SQL Database.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Azure Active Directory Authentication&lt;/strong&gt;: For enhanced security, consider using Azure Active Directory authentication instead of SQL Server authentication. This provides seamless integration with Azure AD identities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Database-level Firewall Rules&lt;/strong&gt;: Restrict access to your Azure SQL Database by configuring database-level firewall rules. This ensures that only authorized IP addresses can connect to the database.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;Azure SQL Database, coupled with .NET integration, empowers developers to build scalable, secure, and high-performance applications in the cloud. The combination of ADO.NET, Entity Framework, and powerful management tools makes the development and maintenance of databases straightforward. By following best practices and leveraging the strengths of both technologies, developers can unlock the full potential of Azure SQL Database in their .NET applications, ushering in a new era of efficient and scalable data management in the cloud.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>aspdotnet</category>
      <category>azure</category>
    </item>
  </channel>
</rss>
