dotNet Core 2

Alter response header in Web API to return machine name

Full source code available here. I recently hit a problem where I was getting incorrect responses from a server behind a load balancer. Looking at the logs didn’t help because there was no error.

Loading Config from Multiple Sources with .NET Core 2.x Web Api or MVC

Full source code available here. .NET Core 2 and .NET Core 2.1 offer many ways to load configuration and they are well documented by Microsoft. But there is one scenario that I didn’t see explained.

Using the In-Memory Cache with .NET Core Web API

Full source code available here. If you need to store anything temporarily within an application, you should consider using the In-Memory Cache from Microsoft. In .NET Core it is much easier to use than its predecessor from Framework 4.

Using Dependency Injection with Startup.cs in ASP.NET Core

Full source code available here. Did you know that .NET Core 2 can pass in an instance of any type you want to the Startup.cs constructor? Well you can! Here’s how.

Getting .NET Core 2.1 Preview 2 Working with Visual Studio 2017

About a year ago I wanted to start using .NET Framework 4.7, it should have been an easy process, but wasn’t. After some trial and error if figured it out and wrote a blog post explaining how to get it working.

Setting the Kestrel Port From Appsettings.json

Full source code available CoreWithKestrelFromConfighere. In my previous post I explained how to host Kestrel web server running on (the default) port 5000 as a Windows service. But what if you want to run the server on a different port?

Hosting a .NET Core 2 Kestrel Server in a Windows Service

Full source code available here. If you have been using the Kestrel web server with Framework 4.x, you might already be hosting Kestrel inside a Windows service. But what if you want to use Kestrel with .

Reusing HttpClient with Dependency Injection

Full source code available here. If you are using HttpClient to make requests for you, you might have come across some articles discussing how to reuse HttpClient. They strongly advocate for using a single HttpClient for as many requests as possible, i.

Entity Framework Core 2 Unit Testing in .NET Core 2

Full source code available here. Unit testing Entity Framework used to be quite a chore, but over the past few years it has become significantly easier. In this post I’m going to show you how to use the InMemory database with named instances.

Unit Testing .NET Core 2 Web Api

Full source code available here. Unit testing Web API controllers in .NET Core 2 is very easy. I have very simple GET and POST methods. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [Route("api/[controller]")] public class ValuesController : Controller { [HttpGet] public async Task<IActionResult> Get() { // imagine some db logic List<string> values = new List<string>() { "value1", "value2" }; return Ok(values); } [HttpPost] public async Task<IActionResult> Post([FromBody]string value) { // imagine some db logic return Created("", value); } } Add an xUnit Test Project to your solution.