<?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>DEV Community: Sachin Ghatage</title>
    <description>The latest articles on DEV Community by Sachin Ghatage (@sachin_ghatage).</description>
    <link>https://dev.to/sachin_ghatage</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%2F3548350%2F4d59b1b1-e647-4fad-a2f0-d6cd5772c04f.png</url>
      <title>DEV Community: Sachin Ghatage</title>
      <link>https://dev.to/sachin_ghatage</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sachin_ghatage"/>
    <language>en</language>
    <item>
      <title>Find the difference</title>
      <dc:creator>Sachin Ghatage</dc:creator>
      <pubDate>Tue, 14 Oct 2025 06:25:35 +0000</pubDate>
      <link>https://dev.to/sachin_ghatage/find-the-difference-49kf</link>
      <guid>https://dev.to/sachin_ghatage/find-the-difference-49kf</guid>
      <description>&lt;p&gt;1)SELECT COUNT(*) FROM Employee;&lt;br&gt;
2)SELECT COUNT(ManagerId) FROM Employee;&lt;/p&gt;

&lt;p&gt;First statement counts all the records including nulls&lt;/p&gt;

&lt;p&gt;Second statement counts only non null records&lt;/p&gt;

&lt;p&gt;Difference is small but very much important&lt;/p&gt;

</description>
      <category>sql</category>
      <category>sqlserver</category>
    </item>
    <item>
      <title>What happens when you inject scoped dependency into singleton?</title>
      <dc:creator>Sachin Ghatage</dc:creator>
      <pubDate>Mon, 13 Oct 2025 10:21:53 +0000</pubDate>
      <link>https://dev.to/sachin_ghatage/what-happens-when-you-inject-scoped-dependency-into-singleton-4ie8</link>
      <guid>https://dev.to/sachin_ghatage/what-happens-when-you-inject-scoped-dependency-into-singleton-4ie8</guid>
      <description>&lt;p&gt;leads to thread-safety issues and memory leaks due to EF’s Change Tracker.&lt;br&gt;
It will give InvalidOperationException.&lt;br&gt;
You registered your DbContext as Scoped → one instance per HTTP request.&lt;/p&gt;

&lt;p&gt;You registered your repository/service as Singleton → one instance for the entire application lifetime.&lt;/p&gt;

&lt;p&gt;Your Singleton service depends on Scoped DbContext.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why this is dangerous&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Even if somehow you delayed instantiation and it works:&lt;/p&gt;

&lt;p&gt;You might accidentally share the same DbContext across multiple requests.&lt;/p&gt;

&lt;p&gt;This causes thread-safety issues, stale data, and memory leaks&lt;/p&gt;

</description>
      <category>aspdotnet</category>
      <category>singleton</category>
      <category>scoped</category>
    </item>
    <item>
      <title>Suppose you have duplicate rows in a table. How can you delete all duplicates but keep one copy using SQL only?</title>
      <dc:creator>Sachin Ghatage</dc:creator>
      <pubDate>Sun, 12 Oct 2025 08:01:44 +0000</pubDate>
      <link>https://dev.to/sachin_ghatage/suppose-you-have-duplicate-rows-in-a-table-how-can-you-delete-all-duplicates-but-keep-one-copy-1f8p</link>
      <guid>https://dev.to/sachin_ghatage/suppose-you-have-duplicate-rows-in-a-table-how-can-you-delete-all-duplicates-but-keep-one-copy-1f8p</guid>
      <description>&lt;p&gt;using CTE + ROW_NUMBER()&lt;/p&gt;

&lt;p&gt;WITH CTE AS (&lt;br&gt;
 SELECT *,&lt;br&gt;
 ROW_NUMBER() OVER (PARTITION BY Name, DeptId ORDER BY EmpId) AS rn&lt;br&gt;
 FROM Employees&lt;br&gt;
)&lt;br&gt;
DELETE FROM CTE&lt;br&gt;
WHERE rn &amp;gt; 1;&lt;/p&gt;

&lt;p&gt;This will number the records according to name and deptId , starts with 1 contiues until next record with different name and deptid is found this way it will delete all the duplicate records keeping one copy&lt;/p&gt;

</description>
      <category>sql</category>
      <category>rownumber</category>
    </item>
    <item>
      <title>What’s the difference between AddScoped, AddTransient, and AddSingleton in dependency injection?</title>
      <dc:creator>Sachin Ghatage</dc:creator>
      <pubDate>Sun, 12 Oct 2025 07:41:21 +0000</pubDate>
      <link>https://dev.to/sachin_ghatage/whats-the-difference-between-addscoped-addtransient-and-addsingleton-in-dependency-injection-221i</link>
      <guid>https://dev.to/sachin_ghatage/whats-the-difference-between-addscoped-addtransient-and-addsingleton-in-dependency-injection-221i</guid>
      <description>&lt;p&gt;AddSingleton - One instance is created and shared for the entire application lifetime (across all HTTP requests).&lt;br&gt;
eg)Logging,Caching&lt;/p&gt;

&lt;p&gt;AddScoped - A new instance is created per HTTP request and shared within that same request.&lt;br&gt;
eg)DbContext&lt;/p&gt;

&lt;p&gt;AddTransient - A new instance is created every time it’s requested (even within the same HTTP request).&lt;br&gt;
eg)EmailService&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>What’s the difference between IActionResult and ActionResult&lt;T&gt; in ASP.NET Core Web API?</title>
      <dc:creator>Sachin Ghatage</dc:creator>
      <pubDate>Sun, 12 Oct 2025 07:13:37 +0000</pubDate>
      <link>https://dev.to/sachin_ghatage/whats-the-difference-between-iactionresult-and-actionresult-in-aspnet-core-web-api-1ei6</link>
      <guid>https://dev.to/sachin_ghatage/whats-the-difference-between-iactionresult-and-actionresult-in-aspnet-core-web-api-1ei6</guid>
      <description>&lt;p&gt;IActionResult is an interface that represents a general action result. You can return any kind of HTTP response, such as Ok(), NotFound(), BadRequest(), etc. It doesn’t specify the type of data being returned.&lt;/p&gt;

&lt;p&gt;public IActionResult GetUser()&lt;br&gt;
{&lt;br&gt;
 var user = _userService.GetUser();&lt;br&gt;
 if (user == null)&lt;br&gt;
 return NotFound();&lt;br&gt;
 return Ok(user);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;ActionResult is a generic type that allows you to return either a typed object (T) or an HTTP response. It combines the flexibility of IActionResult with the strong typing of T.&lt;/p&gt;

&lt;p&gt;public ActionResult GetUser()&lt;br&gt;
{&lt;br&gt;
 var user = _userService.GetUser();&lt;br&gt;
 if (user == null)&lt;br&gt;
 return NotFound();&lt;br&gt;
 return user; // Directly return T (User)&lt;br&gt;
}&lt;/p&gt;

</description>
      <category>aspnet</category>
      <category>web</category>
      <category>api</category>
      <category>actionresult</category>
    </item>
    <item>
      <title>What’s the difference between AddScoped, AddTransient, and AddSingleton in dependency injection?</title>
      <dc:creator>Sachin Ghatage</dc:creator>
      <pubDate>Sun, 12 Oct 2025 07:11:49 +0000</pubDate>
      <link>https://dev.to/sachin_ghatage/whats-the-difference-between-addscoped-addtransient-and-addsingleton-in-dependency-injection-371p</link>
      <guid>https://dev.to/sachin_ghatage/whats-the-difference-between-addscoped-addtransient-and-addsingleton-in-dependency-injection-371p</guid>
      <description>&lt;p&gt;What’s the difference between AddScoped, AddTransient, and AddSingleton in dependency injection?&lt;/p&gt;

&lt;p&gt;AddSingleton - One instance is created and shared for the entire application lifetime (across all HTTP requests).&lt;br&gt;
eg)Logging,Caching&lt;/p&gt;

&lt;p&gt;AddScoped - A new instance is created per HTTP request and shared within that same request.&lt;br&gt;
eg)DbContext&lt;/p&gt;

&lt;p&gt;AddTransient - A new instance is created every time it’s requested (even within the same HTTP request).&lt;br&gt;
eg)EmailService&lt;/p&gt;

</description>
      <category>aspnet</category>
      <category>dependency</category>
      <category>scopes</category>
    </item>
    <item>
      <title>ASP.NET Core Middleware Order Explained: Why app.UseAuthentication() Must Come Before app.UseAuthorization()</title>
      <dc:creator>Sachin Ghatage</dc:creator>
      <pubDate>Mon, 06 Oct 2025 09:05:49 +0000</pubDate>
      <link>https://dev.to/sachin_ghatage/aspnet-core-middleware-order-explained-why-appuseauthentication-must-come-before-26je</link>
      <guid>https://dev.to/sachin_ghatage/aspnet-core-middleware-order-explained-why-appuseauthentication-must-come-before-26je</guid>
      <description>&lt;p&gt;When building an ASP.NET Core application, middleware order is critical. Two common middlewares are app.UseAuthentication() and app.UseAuthorization().&lt;/p&gt;

&lt;p&gt;** What they do**&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;app.UseAuthentication():&lt;/strong&gt; Checks and validates the user's credentials. It sets the HttpContext.User property.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;app.UseAuthorization():&lt;/strong&gt; Uses the authenticated identity to check whether the user has permission to access a resource.&lt;/p&gt;

&lt;p&gt;✅** Correct Order**&lt;br&gt;
app.UseAuthentication();&lt;br&gt;
app.UseAuthorization();&lt;/p&gt;

&lt;p&gt;This order is essential because authentication must happen before authorization. Authorization relies on an authenticated user identity to decide access rights.&lt;/p&gt;

&lt;p&gt;⚠️ &lt;strong&gt;What happens if you reverse the order&lt;/strong&gt;&lt;br&gt;
app.UseAuthorization();&lt;br&gt;
app.UseAuthentication();&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If reversed:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;UseAuthorization runs before UseAuthentication, so HttpContext.User will be empty.Authorization fails because the user hasn’t been authenticated yet.&lt;/p&gt;

&lt;p&gt;The result: authorization will not work as expected, and access to protected resources will be denied even for valid users.&lt;/p&gt;

&lt;p&gt;💡 Key takeaway&lt;/p&gt;

&lt;p&gt;Always place app.UseAuthentication() before app.UseAuthorization() in your middleware pipeline. This ensures proper authentication and authorization flow.&lt;/p&gt;

</description>
      <category>aspnetcore</category>
      <category>dotnet</category>
      <category>middleware</category>
      <category>webapi</category>
    </item>
  </channel>
</rss>
