David Grace - Round The Code

743 posts

David Grace - Round The Code banner
David Grace - Round The Code

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 🎥

Worthing, United Kingdom Bergabung Nisan 2013
137 Mengikuti391 Pengikut
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
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-…
English
0
0
2
225
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
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.
David Grace - Round The Code tweet media
English
1
0
1
185
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
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…
YouTube video
YouTube
English
0
0
1
161
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
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.
David Grace - Round The Code tweet media
English
0
0
1
90
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
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.
David Grace - Round The Code tweet media
English
1
0
4
111
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
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…
YouTube video
YouTube
English
0
0
0
67
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
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.
David Grace - Round The Code tweet media
English
0
0
1
83
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
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().
David Grace - Round The Code tweet media
English
0
0
0
48
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
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.
David Grace - Round The Code tweet media
English
0
0
0
45
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
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.
David Grace - Round The Code tweet media
English
0
0
2
76
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
.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…
YouTube video
YouTube
English
0
0
0
55
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
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();
David Grace - Round The Code tweet media
English
0
0
0
55
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
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…
YouTube video
YouTube
English
0
0
0
37
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
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.
David Grace - Round The Code tweet media
English
0
0
0
43
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
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.
David Grace - Round The Code tweet media
English
0
0
0
35
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
Useful .NET xUnit commands: Creates xUnit project: dotnet new xunit Adds NuGet package dotnet add package Moq Runs a test: dotnet test
English
0
0
0
41
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
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
English
0
0
0
41
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
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.
David Grace - Round The Code tweet media
English
0
0
0
54
David Grace - Round The Code
David Grace - Round The Code@RoundTheCode·
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.
David Grace - Round The Code tweet mediaDavid Grace - Round The Code tweet media
English
0
0
1
49