Posts

Create clean architecture with ASP.NET Core API

  Create clean architecture with ASP.NET Core API Here’s a high-level overview of a clean architecture API setup: /MyApp ├ ── /API                 → Presentation layer (Controllers) ├ ── /Application         → Business logic (use cases, DTOs, interfaces) ├ ── /Domain              → Core models and business rules ├ ── /Infrastructure      → Data access, external services └── /Persistence         → EF Core repositories and DB context 👉 Step-by-Step Setu p : 1.       Create Solution & Project : (use command in terminal for create Solution and project) 👇 dotnet new sln -n MyApp dotnet new webapi -n MyApp.API dotnet new classlib -n MyApp.Application dotnet new classlib -n MyApp.Domain dotnet new classlib -n MyApp.In...

Threading with Mutex

A Mutex is like a C# lock, but it can work across multiple processes. In other words, Mutex can be computer-wide as well as application-wide. A Mutex is a synchronization primitive that can also be used for interprocess synchronization. When two or more threads need to access a shared resource at the same time, the system needs a synchronization mechanism to ensure that only one thread at a time uses the resource. Mutex is a synchronization primitive that grants exclusive access to the shared resource to only one thread. If a thread acquires a Mutex, the second thread that wants to acquire that Mutex is suspended until the first thread releases the Mutex. In short, A mutual exclusion ("Mutex") is a mechanism that acts as a flag to prevent two threads from performing one or more actions simultaneously. The entire action that you want to run exclusively is called a critical section or protected section. A critical section is a piece of code that accesses a shared resource...

You can't update multiple tables in one statement

UPDATE Table1 , Table2 SET Table1 . LastName = 'DR. XXXXXX' , Table2 . WAprrs = 'start,stop' FROM Table1 T1 , Table2 T2 WHERE T1 . id = T2 . id and T1 . id = '010008'   You can't update multiple tables in one statement, however, you can use a transaction to make sure that two   UPDATE   statements are treated atomically. You can also batch them to avoid a round trip. BEGIN TRANSACTION ; UPDATE Table1 SET Table1 . LastName = 'DR. XXXXXX' FROM Table1 T1 , Table2 T2 WHERE T1 . id = T2 . id and T1 . id = '011008' ; UPDATE Table2 SET Table2 . WAprrs = 'start,stop' FROM Table1 T1 , Table2 T2 WHERE T1 . id = T2 . id and T1 . id = '011008' ; COMMIT ; you can't update two tables at once, but you can link an update into an insert using OUTPUT INTO, and you can use this output as a join for the second update: DECLARE @ ids TABLE ( id int ); BEGIN TRANSACTION UPDATE Table1 S...