Ali Hamza Ansari

Ali Hamza Ansari

Meet Ali, a talented .NET developer from Pakistan. Besides blogging, Ali works for a range of international customers doing everything from C# to Azure.

71 posts •
What's new in .NET 9: Two new LINQ methods

Shows .NET 9's two new LINQ methods replacing GroupBy chains on a Student(Name, Subject) list: CountBy collapses GroupBy().Select(Count) into one call, producing Java: 2, C#: 3, JavaScript: 1, while AggregateBy replaces GroupBy().Sum() to total each subject's Marks in a single seeded aggregation. ...

Exploring C# 11 Features: What's New and How to Use It

Demonstrates five C# 11 features with runnable examples: triple-quoted raw string literals for unescaped quotes, list pattern matching like values is [10, 20, 30, ..], UTF-8 string literals via the u8 suffix, required members enforcing FirstName and Email at object initialization, and generic math. ...

What's new in .NET 9: Cryptography improvements

Covers two .NET 9 cryptography additions: CryptographicOperations.HashData for one-shot hashing by naming an algorithm like SHA256, and the new KMAC classes (Kmac128, Kmac256, KmacXof128/256) for message authentication, with a Kmac128.HashData example and its Linux OpenSSL 3.0/Win11 requirements. ...

Boosting Code Readability and Manageability in ASP.NET Core

Presents five ASP.NET Core extension-method patterns: an IServiceCollection.InjectedServices method that consolidates dozens of DI registrations out of Program.cs, a string.IsValidEmail() validator built on MailAddress, and a ClaimsPrincipal.IsOneOf(params string[] roles) helper for role checks. ...

3 Essential Techniques for Managing Transactions in EF Core

Compares three EF Core transaction techniques on a Building entity: automatic transactions where each SaveChangesAsync call is its own implicit transaction, manual transactions wrapping multiple SaveChangesAsync calls via Database.BeginTransaction, and a strategy using CommitAsync for retries. ...

Caching Strategies in ASP.NET Core

Walks through implementing in-memory caching in ASP.NET Core with the Microsoft.Extensions.Caching.Memory package, covering IMemoryCache injection, absolute and sliding expiration settings, and a CustomerRepository example tested with a debugger. ...

How to implement customized role permissions in ASP.NET Core

Builds custom role permissions into an inventory management ASP.NET Core API: wiring up JWT bearer auth with Swagger, then modeling hierarchical permissions like UserCreate and MaterialStockUpdate via EF Core migrations. ...

Custom model validation attributes in ASP.NET Core

Builds a CustomerDateOfBirthValidation attribute by inheriting ValidationAttribute and overriding IsValid, enforcing an 18-year minimum age with DateTime.TryParse checks - a step-by-step alternative to built-in attributes like Required and StringLength. ...