Skip to main content

31 posts tagged with "C#"

View All Tags

· 11 min read
Adnan Rafiq
Title Image of the blog

The .NET migration from ASP.NET Framework 4.x to ASP.NET6 or upcoming ASP.NET8 is going to be on the rise in the next few years due to different reasons. Your reasons may vary from pure business value to upgrading the stack to use better tools & resources. Some teams may even do it to reduce the bill or for the heck of it. All are valid reasons.

One of the team with my current Employer is migrating a .NET Framework 4.x web application to .NET6 which serves up to 4K concurrent users. Before going to production, there is a process to certify the release by running a load test for at least 1X of the expected load which is 4K concurrent users in this application.

During the load test application started to experience a huge number of errors, mainly two types:

  • Sql Connection pool ran out of connections.
  • A key web service started throwing exceptions while communicating with the service. It is a SOAP service which is consumed using WCF Core Client Proxy with basicHttpBinding.

The ASP.NET Framework 4.x version of the application did not experience these problems. So what changed in .NET6 and how will you find out what is wrong? Because there are thousands of different requests at play.

Youtube Video

I have recorded a detailed YouTube video if you prefer the video content.

Detect ASP.NET Core Hangs

· 26 min read
Adnan Rafiq
Understand Middleware Intuitively

What will you learn?

It is a long blog post, but it builds the foundation and deep understanding of the middleware in the ASP.NET 8 or previous versions starting with ASP.NET 6.

It explores middleware, introduces you to HTTP middleware and ASP.NET middleware. It deep dives how the ASP.NET middleware works & how it is actually built. Then you will learn different ways to create middleware in .NET and their pros and cons. Finally, you will build your own middleware pipeline using the ASP.NET approach. Do not miss the copy & paste console sample to debug the .NET like middleware pipeline.

The Middleware

What comes to your mind when you hear the word middleware?

Middle of nowhere. 🃏😆 But that's not the case here.

In the middle of two soft(wares), right? But in the context of the ASP.NET 8 why do you need it? What does it do? How does it work?

· 9 min read
Adnan Rafiq
ASP.NET 8 Configurations With no magic strings

ASP.NET 8 Configurations

Do you love magic strings to get the configuration values? No. Me neither. It was a serious question except you are in JS/TS land.

The amazing .NET supports strongly typed configurations. After all, it is a typed language.

Let me show you the complete usage of strongly typed configurations in ASP.NET 8.

· 16 min read
Adnan Rafiq
ASP.NET 8 Configurations Simple but YET Complex Story Image

ASP.NET 8 Configurations Think about a piece of software; it could be a web or mobile application or an API. What's its purpose? Well, it's here to solve a single or multiple problems for you by offering a suite of unique features.

Now, let's say some of you are fans of a dark theme, while others love the bright hues of a light theme. How can one software cater to both tastes?

Enter Configurations!

· 7 min read
Adnan Rafiq
Title Image of the blog

Records - A Reference Type were introduced in C#9 and extended in C#10 to allow record struct - A Value Type. What is so special about records that the .NET team shipped them in two consecutive releases. In nutshell C# lacked a immutable type with true value equality semantics with a short syntax. Records solves this problem. In this post you will learn:

  • Concise Syntax - Positional Properties
  • Value Equality
  • Immutability
  • Non-Destructive Mutation
  • Deconstruction
  • DDD Value Object using records only

Does this make you curious? I am excited to share this with you.

Youtube Video

I have recorded a detailed Youtube video, if you prefer the video content.

Unlock the Powers of C# Record

· 5 min read
Adnan Rafiq
Start and Finish Image

Image by JetBrains Linkedin

The refactoring of legacy applications is the most valuable skill, you must continuously learn. The ASP.NET Framework 4.x applications are considered legacy, and the dependency injection was not part of the framework. In recent survey done by JetBrains on Linkedin, 46% developers voted the legacy applications as their biggest challenge. In this blog post, you will learn how to incrementally enable DI in ASP.NET 4.8 Web Api application which does not use any sort of DI mechanism, not even poor man DI.

· 4 min read
Adnan Rafiq
Start and Finish Image

Image by @claybanks

Overview

I am working on migrating the .NET Framework application to the .NET6. Since the application was initially written in the .NET Framework 2.0 thus it contains the legacy approaches to get the data from the database. We were using the old version of Microsoft Enterprise Library Data Access package to get the data from the database which is not compatible with the .NET Standard 2.0. So I decided to generate the code for stored procedures using the Dapper and Handlebars templates.

I faced two problems:

  • SQL Server system tables does not know about stored procedure parameter nullability
  • When you are using conditional logic inside the stored procedure, sql server does not give you correct count of the result sets.

· 2 min read
Adnan Rafiq
Start and Finish Image

Image by @claybanks

Authorization Policy

Authorizing the resource access is essential part of any API. The .NET provides you a perfect mental model which is easier to reason about. It has this flow:

  1. What is the name of your policy as string.
  2. What requirement the user must satisfy to qualify which implements the IAuthorizationRequirement interface.
  3. What is your handler responsible to evaluate, which inherits the AuthorizationHandler<UniqueIdHeaderRequirement> and register it.

Then Authorize attribute allows you to set a policy name when used on controller or action method. But if you are fan of Minimal API then fluent style is the way to go using RequireAuthorization.