Posts

CQRS in .NET: When It Makes Sense and When It Doesn't

Every .NET codebase I've worked on that eventually adopted CQRS arrived there the same way: through a service class that nobody wanted to open anymore. You know the one. It starts as JobService . It has CreateJob , GetJobById , and UpdateJob . Reasonable. Six months later it has GetJobForAdminDashboard , GetJobForPublicListing , GetJobWithApplicationCounts , ArchiveExpiredJobs , and a constructor taking nine dependencies because one method needs the email sender, another needs the search indexer, and a third needs the payment client. The file is 1,400 lines. Two of the read methods load full EF Core entities with four Include calls when all they need is a title and a salary range. Somebody added a bool sendNotification = true parameter in 2023 and now four call sites pass false . Nothing here is a disaster. That's exactly the problem. It degrades slowly enough that no single commit looks wrong. At some point someone says "we should look at CQRS," and the team eit...

Struggling with Active Links in Next.js? This Hook Solves It!

Tired of writing complex logic to highlight active navigation links in Next.js? Say hello to   useIsActivePath —a simple yet powerful custom hook that handles all edge cases for you! The Problem with Active Links in Next.js Manually checking  pathname  for active states gets messy: Exact paths ( /about ) Dynamic routes ( /blog/[slug] ) Relative paths ( about  vs  /about ) Wildcard matching ( /docs*  for nested routes) Most solutions require repetitive code — but not anymore! The Solution:  useIsActivePath  Hook This tiny hook does all the heavy lifting: import useIsActivePath from "./useIsActivePath" ; const NavItem = ({ path, label }) => { const isActive = useIsActivePath(path); return <Link href={path} className={isActive ? "text-blue-500" : ""}>{label}</Link>; }; Key Features ✔  Exact matches  ( /dashboard ) ✔  Relative paths  ( dashboard  →  /dashboard ) ✔  Wildcard support  ( /blog*...

Handling Refresh Tokens in React with Redux Toolkit: A Step-by-Step Guide

In modern web applications, maintaining a secure user session is essential. Token-based authentication with access tokens and refresh tokens is a popular solution, but implementing it properly requires a bit of setup to ensure a smooth experience. In this blog post, we’ll go over how to handle refresh tokens in a React application using Redux Toolkit. We’ll set up a custom  baseQueryWithReauth  function that automatically manages the token lifecycle, ensuring users remain authenticated without needing to re-login constantly. Why Use Access Tokens and Refresh Tokens? Access tokens are typically short-lived and allow users to access protected resources without needing to log in again. When these tokens expire, refresh tokens (which are longer-lived) allow the app to request a new access token without interrupting the user experience. This approach not only improves security but also enhances usability. Let’s jump into implementing this in a React app. Step 1: Setting Up the Redu...