How To

InvalidOperationException: Unable to resolve service for type
By Tan Lee Published on Feb 04, 2025 600

When the built-in dependency injection framework attempts to create an object, it needs to resolve all constructor parameters.

How to supply IOptions in ASP.NET Core
By Tan Lee Published on Feb 04, 2025 197

The options pattern in C# allows you to inject settings into a registered service through dependency injection. If your code uses this pattern, you will need to provide an IOptions<T> object.

Logging requests and responses in ASP.NET Core
By Tan Lee Published on Feb 04, 2025 276

In ASP.NET Core, logging HTTP requests and responses is a crucial aspect of monitoring and debugging applications.

How to manually validate a model in a controller in ASP.NET Core
By Tan Lee Published on Feb 04, 2025 333

Validating a model manually in ASP.NET Core can be approached in different ways, depending on your needs. You may want to validate a model object using its validation attributes, or you might need to apply custom validation logic.

How to add custom middleware in ASP.NET Core
By Tan Lee Published on Feb 04, 2025 301

In ASP.NET Core, the request pipeline is a series of middleware components that handle HTTP requests.

How to Turn Off Startup Logging in ASP.NET Core
By Tan Lee Published on Feb 04, 2025 278

When you launch an ASP.NET Core web application, you might notice several startup log messages in the console.

Dependency inject BackgroundService into controllers
By Tan Lee Published on Feb 04, 2025 136

To inject a BackgroundService into controllers in ASP.NET Core, you can't directly inject it through constructor injection like a normal service.

How to Configure JSON Serializer options in ASP.NET Core
By Tan Lee Published on Feb 04, 2025 451

ASP.NET Core uses System.Text.Json as the default JSON serializer. To customize the JSON serializer options globally, you can use the AddJsonOptions() method in the initialization code.

How to use Dictionary with tuples in C#
By Tan Lee Published on Dec 20, 2024 545

You can use dictionaries with tuples as either keys or values in C#.

How to Get all loaded assemblies in C#
By Tan Lee Published on Feb 04, 2025 286

In C#, you can get all loaded assemblies by using the AppDomain.CurrentDomain.GetAssemblies() method.

How to Get all classes that implement interface in C#
By Tan Lee Published on Feb 04, 2025 338

You can use reflection to retrieve all classes in the current assembly that implement a specific interface.

How to Use Convert.ChangeType to convert string to any type in C#
By Tan Lee Published on Feb 04, 2025 454

You can utilize Convert.ChangeType() to transform a string into any type, like this: