Skip to main content

6 posts tagged with ".NET8"

View All Tags

· 3 min read
Adnan Rafiq
How to use Serilog with Application Builder

Logging

Logs are facts emitted by your application especially when it is running in production.

Structured logging is a way to give facts a shape so that you can query logs better.

Serilog is a structured logging library for .NET and it is one of the most popular logging libraries in .NET.

But how to use Serilog with the new .NET 8 Worker template?

· 4 min read
Adnan Rafiq
Validate Options on Startup

Validate Options<T> on Startup in .NET 8

The .NET 8 Host Builder allows you to bind configuration with C# objects by using AddOptions<T> and binding to the configuration.

It provides you an opportunity to validate the configuration values when the host (WebApplication or Hosted Server) is starting by using ValidateOnStart.

But there are two interesting aspects of it, which I will explain in this post.

· 8 min read
Adnan Rafiq
Validate Options on Startup

Validate Options<T> on Startup

The .NET 8 Host Builder allows you to bind configuration with C# objects by using AddOptions<T> and binding to the configuration.

It provides you an opportunity to validate the configuration values when the host (WebApplication or Hosted Server) is starting by using ValidateOnStart.

But there are two interesting aspects of it, which I will explain in this post.

· 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.

· 15 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!

Configurations help us customize how the software behaves. Interesting fact: this customization isn't always about you, the end-user. Behind the scenes, developers also utilize configurations to fine-tune the software's behavior, such as determining which database to connect to, adjusting log level based on the environment, deciding on scaling parameters, and more. Intriguing, isn't it?

In the same sense as a developer, the ASP.NET 8 is a software (framework) that solves a problem for you. Let's start with Web Application Host Builder in ASP.NET 8.

The WebApplication Host Builder

What comes to your mind when you think about the word Host?

A Host takes care of you. Remember, the last time you visited your Aunt’s home, the food, the movies, and everything they made possible for you.

But we are talking about the .NET, a cross-platform framework. What possible relevance does it have with Aunt’s home visit?

Well, the .NET Host takes care of your application by providing out-of-the-box features such as:

  • Configuration
  • Logging
  • Dependency Injection

and many more.