RoundTheCode's profile picture. .NET enthusiast 🚀 | Visit my website for .NET tutorials, code examples, and coding challenges 💻 | Teaching .NET through my YouTube channel 🎥

David Grace - Round The Code

@RoundTheCode

.NET enthusiast 🚀 | Visit my website for .NET tutorials, code examples, and coding challenges 💻 | Teaching .NET through my YouTube channel 🎥

To practice C#, you could turn on your computer and wait for Visual Studio to load. But wouldn't it be good to practice online? Check out my online code editor so you can practice your C# coding skills with this coding challenge to convert mph to kph. roundthecode.com/dotnet-coding-…


You can call EnsureSuccessStatusCode in a HttpResponseMessage type when making an API call in your .NET project. With this line, if an unsuccessful status code is returned from the HTTP response, it will throw an exception.

RoundTheCode's tweet image. You can call EnsureSuccessStatusCode in a HttpResponseMessage type when making an API call in your .NET project.

With this line, if an unsuccessful status code is returned from the HTTP response, it will throw an exception.

Learn about adding SignalR to your ASP .NET Core project so you can add real-time communication. As well as sending and receiving messages, you'll also learn about how to send messages to different connected clients. Watch my video to find out more. youtube.com/watch?v=Mhgb_D…

RoundTheCode's tweet card. Use SignalR to send and receive a message in real-time

youtube.com

YouTube

Use SignalR to send and receive a message in real-time


You can call multiple asynchronous jobs and await all of them to complete by using Task.WhenAll. Task.WhenAll will only be completed when all tasks specified in its parameters are completed.

RoundTheCode's tweet image. You can call multiple asynchronous jobs and await all of them to complete by using Task.WhenAll.

Task.WhenAll will only be completed when all tasks specified in its parameters are completed.

Feature Management in ASP .NET Core allows you to add feature flags. You do it by adding the Microsoft.FeatureManagement.AspNetCore NuGet package and calling AddFeatureManagement extension method.

RoundTheCode's tweet image. Feature Management in ASP .NET Core allows you to add feature flags.

You do it by adding the Microsoft.FeatureManagement.AspNetCore NuGet package and calling AddFeatureManagement extension method.

Learn about SignalR and how to send and receive a message back from a hub. Messages can be sent to all clients, or to particular clients. roundthecode.com/dotnet-tutoria…


You can use IConfiguration, IOptions or IOptionsSnapshot to get appsettings configuration values into an ASP .NET Core application. But which one should you use? Watch my video to find out. youtube.com/watch?v=FAV1Xt…

RoundTheCode's tweet card. How should you get config values from appsettings.json?

youtube.com

YouTube

How should you get config values from appsettings.json?


When creating a custom scope in a .NET project, you can now create it asynchronously. The 'await' keyword has to appear before the 'using' statement, and you call the CreateAsyncScope.

RoundTheCode's tweet image. When creating a custom scope in a .NET project, you can now create it asynchronously.

The 'await' keyword has to appear before the 'using' statement, and you call the CreateAsyncScope.

To add the default extensions to wwwroot files in ASP .NET Core, you can add app.UseDefaultFiles() in Program.cs. This will add Default and Index (.htm and .html) as default files for a folder. It must be called before app.UseStaticFiles().

RoundTheCode's tweet image. To add the default extensions to wwwroot files in ASP .NET Core, you can add app.UseDefaultFiles() in Program.cs.

This will add Default and Index (.htm and .html) as default files for a folder.

It must be called before app.UseStaticFiles().

If you want to use IHttpClientFactory outside of ASP .NET Core, you can add Microsoft.Extensions.DependencyInjection and Microsoft.Extensions.Http to your project. Then build a service collection by adding your HttpClient to it.

RoundTheCode's tweet image. If you want to use IHttpClientFactory outside of ASP .NET Core, you can add Microsoft.Extensions.DependencyInjection and Microsoft.Extensions.Http to your project.

Then build a service collection by adding your HttpClient to it.

In SignalR, you can use Clients.All to invoke a method to all connected clients. However, you can invoke a method to the connected client by using Clients.Client(Context.ConnectionId). This is handy if you want to send a message back after they sent one.

RoundTheCode's tweet image. In SignalR, you can use Clients.All to invoke a method to all connected clients.

However, you can invoke a method to the connected client by using Clients.Client(Context.ConnectionId).

This is handy if you want to send a message back after they sent one.

.NET 7 has now reached end-of-life meaning it's time to update! By not doing so risks your application's security. That's because Microsoft will no longer make any more updates to .NET 7 & won't put in fixes for newly found bugs. Watch my video for more: youtube.com/watch?v=Eywsbo…

RoundTheCode's tweet card. .NET 7 apps must be updated now to stop vulnerabilities

youtube.com

YouTube

.NET 7 apps must be updated now to stop vulnerabilities


You can add custom middleware to your ASP .NET Core app by using app.Use. This example will add a response header of X-Frame-Options with a value of SAMEORIGIN. You can also add it in a class and register it by using app.UseMiddleware();

RoundTheCode's tweet image. You can add custom middleware to your ASP .NET Core app by using app.Use.

This example will add a response header of X-Frame-Options with a value of SAMEORIGIN.

You can also add it in a class and register it by using app.UseMiddleware();

Have you tried using VS Code to develop a .NET application? Watch my video where we develop an Web API project and run it using Visual Studio Code. How does it compare to Visual Studio? youtube.com/watch?v=ljXDKB…

RoundTheCode's tweet card. What's it like using VS Code to build a .NET project?

youtube.com

YouTube

What's it like using VS Code to build a .NET project?


You can use a scoped service in a .NET background task like a hosted service. Inject the IServiceProvider instance, and then call the CreateScope method within it. You can use that scope instance to resolve a scoped service.

RoundTheCode's tweet image. You can use a scoped service in a .NET background task like a hosted service.

Inject the IServiceProvider instance, and then call the CreateScope method within it.

You can use that scope instance to resolve a scoped service.

Theory in xUnit allows you to add parameterised tests. You can add [InlineData] with [Theory] to your tests and add the parameters you wish to test against. This stops adding unit multiple tests for the same logic.

RoundTheCode's tweet image. Theory in xUnit allows you to add parameterised tests.

You can add [InlineData] with [Theory] to your tests and add the parameters you wish to test against.

This stops adding unit multiple tests for the same logic.

Useful .NET xUnit commands: Creates xUnit project: dotnet new xunit Adds NuGet package dotnet add package Moq Runs a test: dotnet test


Useful .NET commands: Creates new Web API project: dotnet new webapi -n MyProject -controllers Creates interface: dotnet new interface --name IMyService Creates class: dotnet new class --name MyService Creates API controller: dotnet new apicontroller --name MyController


If an unhandled exception is thrown in C#, it will always run the finally block if you are using ASP .NET Core. However if you are using a console app, the program will exit before calling the finally block meaning that it will never execute.

RoundTheCode's tweet image. If an unhandled exception is thrown in C#, it will always run the finally block if you are using ASP .NET Core.

However if you are using a console app, the program will exit before calling the finally block meaning that it will never execute.

IOptionsSnapshot allows you to bind config values from appsettings into a class. You add the options in Program.cs and can inject IOptionsSnapshot adding the config class as the generic type. It has a scoped lifetime scope meaning values can change without restarting the app.

RoundTheCode's tweet image. IOptionsSnapshot allows you to bind config values from appsettings into a class.

You add the options in Program.cs and can inject IOptionsSnapshot adding the config class as the generic type.

It has a scoped lifetime scope meaning values can change without restarting the app.
RoundTheCode's tweet image. IOptionsSnapshot allows you to bind config values from appsettings into a class.

You add the options in Program.cs and can inject IOptionsSnapshot adding the config class as the generic type.

It has a scoped lifetime scope meaning values can change without restarting the app.

Loading...

Something went wrong.


Something went wrong.