Friday, August 1, 2025

How to Do Cross-Browser Testing on Windows — Including Safari via Playwright

To test follow few steps:

Step 1. Install node
Step 2. create Folder and run these commands

commands


Step 3. update package.json 's scripts

package.json


Step 4. create Test folder in above folder and create file with name browser.test.ts and add below code

browser.test.ts


Step 5. run command npm run test:safari

Friday, July 18, 2025

How to Highlight a Link of Side Nav When It Has Multiple Child Links in Angular

๐Ÿ”— How to Highlight a Link When It Has Multiple Child Links in Angular

When building a sidebar in Angular, you might want to highlight a parent link when any of its child routes are active. Angular’s routerLinkActive only works for single routes — so here’s a quick 2-step solution using a custom directive.

  1. Step 1: Create a custom directive
    Write a directive that checks the current URL against a list of child links and adds an active class if any match.

Step 1: Directive Code

  1. Step 2: Use it in your template
    On your parent menu link, pass the list of child URLs to the directive.

Step 2: Template Code

✅ Works with multiple child links, query parameters, and is easy to reuse.

✅ This blog is written by TechJourney with Gagan, sharing practical Angular tips for developers.

Tuesday, July 1, 2025

Create Search Functionality using 2 steps using pipe in Angular

To Implement Search Functionality without writing code in ts file

Step1: Create a Pipe using below code.

Code Of Search Filter Pipe



Step2: write below code where you want to implement search like in drop down.

Code Snippet



In above code we use just
<input matInput  placeholder="Search Company" #searchInput /><br> 
based on referece variable we took input and pass to pipe | searchByFilter:searchInput.value:'organizationName'"

Thursday, June 26, 2025

๐Ÿงฉ Implementing a Lightweight Query Handler in .NET using GMediator fully free for commerical use

In modern .NET applications, maintaining clean architecture is critical — and that’s where the Mediator pattern shines. It decouples the request/response flow and promotes separation of concerns.

While libraries like MediatR are popular, sometimes you want something even lighter — with zero dependencies.

Enter: GMediator, a custom lightweight mediator implementation.


๐Ÿš€ What We’ll Build
In this blog, we’ll create a simple GET API using GMediator that returns a list of products stored in an in-memory store — no database, no ORM — just the core pattern in action.
๐Ÿงฑ Step 1: Define the Product Model

Code Snippet


๐Ÿ’พ Step 2: Create an In-Memory Store

Code Snippet


๐Ÿ“ฌ Step 3: Create the Query Request

Code Snippet


๐ŸŽฏ Step 5: Create the Controller

Code Snippet


๐Ÿงช Step 6: Register GMediator in Program.cs

Code Snippet


๐Ÿ’ก Final Thoughts
GMediator is a great option for internal projects, low-dependency APIs, or learning the Mediator pattern hands-on.
You can extend this by adding Create, Update, Delete, or integrating with a real database like SQLite or SQL Server.

Wednesday, June 11, 2025

Building a Scalable .NET Backend Using Clean Architecture (With Optional Layers) in just an second

If you're building a new .NET backend, Clean Architecture is the best way to keep your code organized, scalable, and future-proof.
๐Ÿงฑ What is Clean Architecture?
It's a way to structure your project into layers:
Domain – core business models
Application – commands, queries, interfaces
Infrastructure – external services (API, logging, etc.)
Persistence – database (EF Core, SQL)
API – controllers
Tests – optional unit/integration tests
⚙️ Script-Based Setup
You can auto-generate this structure using a simple CMD script.
✅ You choose what to include:
Want Infrastructure? Type y
Need Tests? Type n
Want to skip Persistence? Type n




Steps To use:

1. use notepad save below code as setup-architecture.cmd

Code Snippet


2. save this file in respective folder where u want your project files
3. open cmd at this location and run this script by just type its name only that is setup-architecture.cmd

Wednesday, May 28, 2025

๐Ÿ”„ How to Extend Component Logic and Template in Angular (Simple Guide) => use of extends and ngTemplateOutlet

When building Angular apps, you might have common logic or reusable layouts across components. Instead of duplicating code, you can use extends in TypeScript and ng-template + ngTemplateOutlet in HTML.

Let’s walk through a simple example with 2 components where one extends logic and also injects custom HTML.


✅ Step 1: Create a Child Component (as base layout)

This is the reusable component that contains a common layout and logic.

child.component.ts

child.component.html

  • ✅ Layout and logic are defined here.
  • ✅ Accepts external HTML through contentTemplate.

✅ Step 2: Create a Parent Component That Extends Child

This component inherits logic from ChildComponent and injects its own template content.

parent.component.ts

parent.component.html

  • ✅ Inherits logic like title and getTitle() from ChildComponent.
  • ✅ Injects its own content via ng-template.

✅ Final Output

  • ChildComponent provides the reusable layout.
  • ParentComponent injects dynamic HTML and extends the logic.
  • This keeps your code DRY, clean, and scalable.

Use Cases: shared card layouts, reusable modal structures, dashboards, etc.

Friday, May 2, 2025

๐Ÿงน How to Remove SSR (Server Side Rendering) from an Angular 19 Project

Sometimes you add Angular SSR using @angular/ssr, but later want to return to a clean client-side app. Here's how to fully remove SSR (Server-Side Rendering) from your Angular project. ๐Ÿ”ฅ Step 1: Delete SSR Files Remove these files from the src/ folder: main.server.ts app.server.module.ts server.ts Any .server.ts files like: app.routes.server.ts app.config.server.ts ๐Ÿ› ️ Step 2: Update angular.json Inside "architect > build > options", remove the following: Also remove the entire "server" block from angular.json if it exists. ๐Ÿงพ Step 3: Clean Up TypeScript Config ❌ Delete: tsconfig.server.json ✅ Edit tsconfig.app.json like this: ๐Ÿงน Step 4: Uninstall SSR Dependencies ๐Ÿ–ฅ️ Run in Terminal / PowerShell / CMD: ๐Ÿš€ Step 5: Clean & Serve PowerShell (Windows): Mac/Linux terminal: ✅ Done! Your Angular app is now SSR-free and runs entirely with Client-Side Rendering (CSR) — faster dev, fewer headaches!

Saturday, March 29, 2025

๐Ÿš€ How to Copy a SQL Server Database Using a .bacpac File (Schema + Data) || Clone DB

#Clone Database 
Need to duplicate a full SQL Server database — including tables, views, stored procedures and data — without writing complex scripts?

Let me show you a simple, reliable method: Exporting and Importing a Data-tier Application (.bacpac). It’s perfect for backups, migrations, and creating dev/test clones.


 Step 1: Export the Source Database

  1. Open SQL Server Management Studio (SSMS).

  2. Right-click your source database → Tasks → Export Data-tier Application.

  3. Choose "Save to local disk", then pick a file path and name (YourDatabase.bacpac).

  4. Click Next through the wizard and generate the .bacpac file.


 Step 2: Import into Target Server

  1. In SSMS, right-click DatabasesImport Data-tier Application.

  2. Select the .bacpac file you exported.

  3. Give the new database a name.

  4. Complete the wizard. ๐ŸŽ‰ Done!


๐Ÿงฉ Diagram

[ Source DB ] | | Export as .bacpac ↓ [ YourFile.bacpac ] | | Import on Target Server ↓ [ New DB Clone ]

Why Use This?

  • ๐Ÿ”„ Migrate databases between environments (dev, staging, prod).

  • ๐Ÿ› ️ Create dev/test clones without risking production.

  • ๐Ÿ“ฆ Archive snapshots with both schema and data.

Friday, March 14, 2025

Run ai model in python code with ollama

 First download and install ollama By this blog:
Tech Journey With Gagan: Run Any AI Model with ollama in windows

For Use AI model in python:
1. run this script
Note: this example for mistral ai model please change acording to your model

Declare function


For run

it is work like this


Option 2: 
Run server explicitly 

1. Click on Quit Ollama


2. run server with ollama serve mean in cmd type "ollama serve".



Run Any AI Model with ollama in windows

Steps for install Any model with ollama in local : 
1. Download Olama  and install 


2.  open cmd and run "ollama" command to verify that ollama installed or not.



3. Install models  
    a. find your model and click on it.

   b. copy command and paste into terminal





                      press Enter now your model installed 

Note :Later on same command run your model will run automatically this time it is not downloading it just run 



How To work python with ollama: Run AI Model with Python

Friday, March 7, 2025

๐Ÿ˜ฎCreate Task Scheduler app using AI Agent in just before 2 min ๐Ÿ˜ฎ



Steps to create :
1. use Cline Agent extention in vs code.
2. use api of AI models like.
3. Give prompt to Cline.
4. Work automatically give you clean app.
Note: No need to create any file it will do automatically.

GitHub Repository Viewer

๐Ÿ“Œ GitHub Repository Viewer

Loading...


Git Hub Repo Link Here

Thursday, March 6, 2025

Building a C# Web API with Onion Architecture, CQRS, MediatR & Quartz.NET CRON Jobs

 


Introduction

In modern C# applications, clean architecture plays a crucial role in maintaining scalability and maintainability. In this blog, we will build a C# Web API using Onion Architecture, CQRS, MediatR, and Quartz.NET for scheduling background jobs. This guide will walk you through structuring a project with best practices and SOLID principles.

Why Use Onion Architecture?

Onion Architecture provides a clear separation of concerns by organizing the application into different layers:

  1. Domain Layer → Contains core business logic and entities

  2. Application Layer → Contains CQRS commands, queries, and interfaces

  3. Infrastructure Layer → Handles database, repository pattern, and external integrations

  4. Presentation Layer (API Layer) → Exposes the application as an API

Tech Stack

  • ASP.NET Core Web API for building RESTful APIs

  • Entity Framework Core for database operations

  • CQRS Pattern for separating read & write operations

  • MediatR for in-memory messaging

  • Quartz.NET for CRON Job scheduling

  • SOLID Principles to make the application scalable

    ๐Ÿ“Œ Project Structure

    Your project will be structured as follows:

    Architecture Snippet

    Step 1: Create the Student Model (Domain Layer)

    ๐Ÿ“ Location: Onion.Domain/Models/Student.cs

    Model Snippet

    Step 2: Create CQRS Commands & Queries (Application Layer)

    ✅ Command to Create a Student

    ๐Ÿ“ Location: Onion.Application/Features/Students/Commands/CreateStudentCommand.cs

    Code Snippet

    ✅ Query to Get All Students

    ๐Ÿ“ Location: Onion.Application/Features/Students/Queries/GetAllStudentsQuery.cs

    Code Snippet

    Step 3: Implement Repository (Infrastructure Layer)

    ๐Ÿ“ Location: Onion.Infrastructure/Repositories/StudentRepository.cs

    Code Snippet

    Step 4: Implement CRON Job Using Quartz.NET

    ๐Ÿ“ Location: Onion.Infrastructure/Scheduler/CronJobService.cs

    Code Snippet

    Step 5: Register Everything in Program.cs (API Layer)

    ๐Ÿ“ Location: Onion.API/Program.cs

    Code Snippet

    Conclusion

    By following this guide, you have successfully built a C# Web API with Onion Architecture, CQRS, MediatR, and Quartz.NET CRON Jobs.
    This approach ensures:
    Scalability using Onion Architecture
    Separation of Concerns (SoC)
    Background Job Execution with Quartz.NET
    Better Maintainability with CQRS & MediatR

    ๐Ÿš€ Download Full Project
    Github

๐Ÿ”ฅ "Building a C# Web API with Onion Architecture, CQRS, MediatR & Quartz.NET CRON Jobs Project" ๐Ÿš€


Cover In this:
✅ Onion Architecture ka Overview
✅ CQRS Pattern + MediatR used
✅ Quartz.NET ke sath CRON Jobs
✅ Dependency Injection & SOLID
✅ GitHub :https://github.com/gaganmanakpuria/AddStudentCronJobWithOnionArchitectureWithSOLID


GitHub Repository Viewer

๐Ÿ“Œ GitHub Repository Viewer

Loading...

Tuesday, February 25, 2025

Efficient Parallel Processing in .NET: Using Parallel.ForEach, IServiceScopeFactory, and ConcurrentBag

Parallel processing in .NET can significantly improve performance when dealing with large collections. However, when working with scoped dependencies and thread-safe collections, managing them properly is crucial. This blog explores how to use Parallel.ForEach, IServiceScopeFactory, and ConcurrentBag efficiently.

Why Use Parallel.ForEach?
Parallel.ForEach executes iterations in parallel, utilizing multiple CPU cores to improve performance. However, it does not automatically handle scoped dependencies from IServiceScopeFactory, which is essential when working with services like DbContext in ASP.NET Core.

Why IServiceScopeFactory?
Since DbContext and other scoped services should not be shared across multiple threads, using IServiceScopeFactory ensures each thread gets its own service scope.

Why ConcurrentBag?
When dealing with concurrent operations, ConcurrentBag is a thread-safe collection that allows multiple threads to add or retrieve items without conflicts.


Example:

Code Snippet


Key Takeaways
- Use Parallel.ForEach for performance gains when processing large collections.
- Utilize IServiceScopeFactory to create scoped services inside parallel loops.
- Store results in ConcurrentBag to ensure thread safety when collecting data.
This approach ensures efficient parallel execution while maintaining the integrity of scoped services in .NET. ๐Ÿš€

Friday, February 14, 2025

๐Ÿš€ Oops! Pushed to develop by Mistake? Here’s a Quick Fix! ๐Ÿš€

๐Ÿš€ Oops! Pushed to develop by Mistake? Here’s a Quick Fix! ๐Ÿš€
We've all been there—accidentally pushing changes to the develop branch instead of a feature branch. Before you panic, there's a simple way to undo it gracefully using Git.

๐Ÿ”„ The Quick Fix
If you've mistakenly pushed your latest commit to develop, run the following command: 1️⃣ Save the commit/changes

Code Snippet


๐Ÿ”น What does this do?
✅ Moves the latest commit to staged changes without deleting it.
✅ Allows you to fix things before re-committing or switching branches.

2️⃣ Discard the Commit Completely
If you want to undo the commit entirely (⚠️ This will remove all changes!):

Discard the Last Commit


๐Ÿ”„ Next Steps
Switch to the Correct Branch and Recommit
If you meant to push the changes to a different branch:

Move Changes to Correct Branch


๐Ÿ˜ŠLike that we can revert our mistake๐Ÿ˜Š

Wednesday, February 12, 2025

How to handle when code push accidently in deleted branch

Have you ever pushed your code, only to realize the branch was deleted? ๐Ÿ˜ฑ No worries—your work isn't lost! Git keeps a history of all commits, and you can easily recover your code.
๐Ÿš€ Steps to Recover Your Deleted Branch
1️⃣ Check Your Git Log Even if a branch is deleted, the commits still exist. Run:

Code Snippet

This will show a list of commit hashes with their messages.
2️⃣ Find Your Last Commit Look for the commit related to your deleted branch
3️⃣ Restore Your Branch Once you have the commit hash, recreate the branch:

Code Snippet

Note : Instead of "abc1234" write "your hashcode" and "recovered-branch" write your "new branch name"

๐Ÿ˜ŠNow you can push your code in that branch and you can able to create PR.๐Ÿ˜Š

Sunday, February 9, 2025

How to Implement In Memory Caching in .net

 

Introduction

In modern web applications, performance is key. Fetching data repeatedly from a database can lead to increased response times and higher server load. One effective way to optimize performance is by using in-memory caching to store frequently accessed data. In this blog, we will explore how to integrate IMemoryCache in an ASP.NET Core Web API project to efficiently handle CRUD operations for a Student entity.

What is In-Memory Caching?

In-memory caching is a mechanism that temporarily stores frequently accessed data in memory, reducing the need to retrieve it from the database each time. ASP.NET Core provides IMemoryCache, which is a simple, high-performance, and thread-safe cache.

Setting Up the Project

To demonstrate in-memory caching, let’s build an ASP.NET Core Web API with a StudentController that performs CRUD operations using Entity Framework Core.

1. Install Required Dependencies

Ensure you have the necessary NuGet packages installed in your ASP.NET Core project:




2. Add Model and  AppDb Context file



Student Model

AppDb Context File

3. Add in Appsettings.json just below of AllowedHosts by put comma

Connection String

4. Add Settings

Program.cs

5. Add-Migration and Update-database run two commands
6. add Controller with name Student

Student Controller

6. SetSlidingExpiration: refreseh if no activity in 10 min
SetAbsoluteExpiration : always refresh after 1 hour

Expalin memory Cache options

Note: In this i used semaphoreslim for single process optimised the in memory cache. I am updating the in memory cache when add and update and delete. also this approch is helpfull for single server or small level applications. for multiserver or high level application we should go with distributed cache technique like redis so our ram not effected to much.

Clone this poc:InMemoryCachePOC

Semaphore Vs Semaphore Slim

 

Semaphore vs SemaphoreSlim in C#

What is a Semaphore?

A Semaphore is a synchronization primitive used to control access to a shared resource by multiple threads. It works by maintaining a count that represents the number of available slots for accessing the resource. When a thread enters, the count decreases, and when it leaves, the count increases.

What is SemaphoreSlim?

SemaphoreSlim is a lightweight, managed implementation of Semaphore, introduced in .NET Framework 4. It provides better performance and is optimized for cases where a semaphore is needed within a single process.


Why Use Semaphore and SemaphoreSlim?

  1. To limit concurrent access to a resource
    Example: Controlling access to a database connection pool or an API rate limit.

  2. To prevent race conditions
    Example: Ensuring that only a limited number of threads can modify a shared collection at a time.

  3. To manage multi-threaded access in an efficient way
    Example: Restricting simultaneous file writes to avoid corruption.


    Semaphore vs SemaphoreSlim - Key Differences ๐Ÿš€

    FeatureSemaphore ๐ŸขSemaphoreSlim ๐Ÿš€
    ScopeWorks across multiple processesWorks within a single process
    ImplementationUses OS-level (kernel-based) synchronizationUses user-mode synchronization (managed by .NET)
    PerformanceSlower due to kernel transitionsFaster as it avoids kernel overhead
    Async SupportDoes not support async/awaitSupports async/await for better responsiveness
    Use CaseInter-process synchronization (e.g., shared system resources)Within-process synchronization (e.g., limiting concurrent API calls, database access)
    Blocking vs Non-BlockingBlocks threads while waitingUses async wait, avoiding thread blocking
    Wait Handle Support✅ Supports WaitOne(), WaitAll()❌ Does not support WaitHandle methods

    When to Use?

    Use Semaphore when you need to synchronize across different applications (e.g., OS-wide named semaphores).
    Use Semaphore Slim when you need a lightweight, high-performance synchronization within a single process, especially with async/await.

    Note: semaphore slim  I used in in memory caching for single process so save dB calls and we give users to fast response.
    while semaphore is used for allow or control to multiple processes like if we have to run only two than we can control with that 
    InMemory caching: In Memory Caching in .Net

Wednesday, February 5, 2025

How .NET API Uses RAM?

✅ Application Start: Code and dependencies are loaded into RAM.

✅ CLR Loads Assemblies: JIT compiles and stores DLLs in RAM.

✅ Memory Allocation: Stack (method calls) & Heap (objects, DI, cache).

✅ Caching (Boosts Speed!): Frequently accessed data is stored in RAM.

✅ Handling HTTP Requests: Kestrel/IIS processes requests in memory.

✅ Garbage Collection: Frees up unused objects, optimizing RAM.

✅ (Optional) In-Memory Database: Uses RAM for high-speed transactions.


๐Ÿ”น Complete Process in a Simple Diagram!


+----------------------------------------------------+

| ๐ŸŸข APPLICATION START (Loaded in RAM) |

| - Run API: (dotnet run / IIS / Kestrel) |

| - .NET Runtime (CLR) loads code into RAM |

+----------------------------------------------------+

|

v

+----------------------------------------------------+

| ๐Ÿ”„ CLR LOADS ASSEMBLIES (Stored in RAM) |

| - JIT (Just-In-Time) compiles code |

| - Dependencies & DLLs loaded into memory (RAM) |

+----------------------------------------------------+

|

v

+----------------------------------------------------+

| ๐Ÿ’พ MEMORY ALLOCATION (RAM Usage) |

| - Stack: Stores method calls, local variables |

| - Heap: Stores objects, services, cache data |

| - DI Container: Manages service lifetimes |

+----------------------------------------------------+

|

v

+----------------------------------------------------+

| ⚡ CACHING (Improves Speed, Uses RAM) |

| - In-Memory Cache (MemoryCache, Singleton) |

| - Distributed Cache (Redis, NCache) (Optional) |

| - Reduces Database Calls, Increases Performance |

+----------------------------------------------------+

|

v

+----------------------------------------------------+

| ๐ŸŒ HANDLING HTTP REQUESTS |

| - Kestrel/IIS Listens for Requests |

| - Middleware (Auth, Logging, Compression) |

| - Controllers Execute Business Logic |

+----------------------------------------------------+

|

v

+----------------------------------------------------+

| ๐Ÿ—‘️ GARBAGE COLLECTION (Frees RAM) |

| - Gen 0: Short-lived objects (frequent cleanup) |

| - Gen 1 & 2: Long-lived objects (less cleanup) |

| - Optimizes RAM usage, prevents memory leaks |

+----------------------------------------------------+

|

v

+----------------------------------------------------+

| ๐Ÿ›ข️ (OPTIONAL) IN-MEMORY DATABASE |

| - EF Core In-Memory / SQLite (Stored in RAM) |

| - Fast Reads/Writes, No Disk I/O |

+----------------------------------------------------+

๐Ÿ’ก Why This Matters?

๐Ÿ”น Faster performance with in-memory caching.

๐Ÿ”น Reduced database calls, improving scalability.

๐Ÿ”น Optimized RAM usage via Garbage Collection.


How to Do Cross-Browser Testing on Windows — Including Safari via Playwright

To test follow few steps: Step 1. Install node Step 2. create Folder and run these commands commands Copy Code ...