<?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: Bruno Ferreira</title>
    <description>The latest articles on DEV Community by Bruno Ferreira (@brunosync).</description>
    <link>https://dev.to/brunosync</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%2F3927951%2Ffb0c5500-d52d-4551-adf0-fd2635c28b7c.png</url>
      <title>DEV Community: Bruno Ferreira</title>
      <link>https://dev.to/brunosync</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/brunosync"/>
    <language>en</language>
    <item>
      <title>I built a NuGet middleware to catch N+1 problems and slow queries in ASP.NET Core</title>
      <dc:creator>Bruno Ferreira</dc:creator>
      <pubDate>Tue, 12 May 2026 20:37:20 +0000</pubDate>
      <link>https://dev.to/brunosync/i-built-a-nuget-middleware-to-catch-n1-problems-and-slow-queries-in-aspnet-core-4e8k</link>
      <guid>https://dev.to/brunosync/i-built-a-nuget-middleware-to-catch-n1-problems-and-slow-queries-in-aspnet-core-4e8k</guid>
      <description>&lt;p&gt;Every .NET developer has been there: the app feels slow, you open the logs, and you find the same query firing 50 times per request. N+1 problems are easy to introduce and annoying to find.&lt;/p&gt;

&lt;p&gt;So I built &lt;strong&gt;DbEye&lt;/strong&gt; — a lightweight ASP.NET Core middleware that detects N+1 query problems and slow queries automatically, per HTTP request, right in your development terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it does
&lt;/h2&gt;

&lt;p&gt;DbEye hooks into EF Core via an interceptor and tracks every query fired during a request. When something looks wrong, it logs a warning directly in your console:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;N+1 detected:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;warn: DbEye[0]
      ⚠️  N+1 detected at GET /api/posts
      Query repeated 100x - SELECT * FROM "Comments" WHERE "PostId" = ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Slow query detected:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;warn: DbEye[0]
      ⚠️  Slow query detected at GET /api/comments
      Duration: 732ms - SELECT * FROM "Comments"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No external dashboard. No extra services to run. Just clear warnings where you already look.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup in 3 lines
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&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;AddDbEye&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;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddDbContext&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;AppDbContext&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;((&lt;/span&gt;&lt;span class="n"&gt;serviceProvider&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;UseNpgsql&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="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddInterceptors&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;serviceProvider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetRequiredService&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;DbEyeInterceptor&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;());&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;UseDbEye&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The default slow query threshold is 500ms. You can change it:&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;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;AddDbEye&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SlowQueryThresholdMs&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;200&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;h2&gt;
  
  
  Try it yourself
&lt;/h2&gt;

&lt;p&gt;The repo includes a demo project with a pre-configured Postgres database. You can trigger real N+1 scenarios and slow queries in under a minute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/BrunoSync/DbEye
&lt;span class="nb"&gt;cd &lt;/span&gt;DbEye
docker compose up
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then hit &lt;code&gt;GET /api/posts&lt;/code&gt; and watch the warnings appear live. Pass &lt;code&gt;?include=true&lt;/code&gt; to fix the N+1 and see DbEye go silent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I built it
&lt;/h2&gt;

&lt;p&gt;I wanted a tool that required zero configuration to give you immediate feedback during development — before a performance problem ever makes it to production. Most solutions I found required either a dashboard, a separate service, or significant setup. DbEye is intentionally minimal.&lt;/p&gt;

&lt;p&gt;It supports .NET 8, 9, and 10 with their corresponding EF Core versions.&lt;/p&gt;




&lt;p&gt;📦 NuGet: &lt;a href="https://www.nuget.org/packages/DbEye" rel="noopener noreferrer"&gt;https://www.nuget.org/packages/DbEye&lt;/a&gt;&lt;br&gt;&lt;br&gt;
⭐ GitHub: &lt;a href="https://github.com/BrunoSync/DbEye" rel="noopener noreferrer"&gt;https://github.com/BrunoSync/DbEye&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feedback, issues, and PRs are very welcome — this is still early and I'd love to hear how it holds up in real projects.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>entityframework</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
