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. Out of the box the Startup.cs comes...
View ArticleUsing 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...
View ArticleLoading 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. If...
View ArticleUsing Other Verbs with Web API
Full source code available here. You will often use the GET verb when making requests to an API. You have probably used it like this – www.example.com/person/ or www.example.com/person/1 or...
View ArticlePolly, HttpClientFactory and the Policy Registry – choosing the right policy...
Full source code available here. The release of .NET Core 2.1 has made using HttpClient much easier. If you have been using HttpClient for a while you will know about its limitations around reuse and...
View ArticlePolly, HttpClientFactory and the Policy Registry in a console application
Full source code available here. How to use the HttpClientFactory with a console application is not immediately obvious. I thought it would be a simple matter, but it’s not because it relies on the...
View ArticleAlter 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. It...
View ArticleSaving Enums with Entity Framework Core
Full source code here. A few years ago I wrote a post about saving enums to the database with Entity Framework. It was able to save the enum as a string to the database and when reading from the...
View ArticleUsing Polly with Any Type of Request
Full source code here. I recently presented a talk on Polly at the DevUp conference in St. Louis. In the presentation I showed examples using Polly with HttpClient requests only because this is my most...
View ArticleCaching in Polly and the HttpClientFactory
Full source code here. Polly allows you to cache a response for reuse by a subsequent request, it supports both local an distributed caches, full information can be found here...
View ArticleDynamically Updating the Request Header of a HttpClientFactory Generated...
Full source code here. There are some subtle issues in the way I use DI in this post, see here for an alternative if you don’t want to follow this approach While using the HttpClientFactory I hit a...
View ArticleHow to Turn Off Console Logging for Kestrel in .NET Core
This post is mostly a note to myself. I am often annoyed with the amount of logging to the console that occurs when I start a Kestrel hosted application and I can never remember how to turn it off....
View ArticleDynamically Updating the Request Header of a HttpClientFactory Generated...
Full source code here. This is a alternative to the approach described in a previous post. On a slack channel there was some discussion around the use of a little known extension method on...
View ArticleHow to Dependency Inject a Service from Startup back in Program
Full source code here. While writing some recent blog posts on HttpClientFactory I had to work with some of the obscure features of ServiceCollection and dependency injection in .NET Core 2.1. One of...
View ArticleHow to use HttpClientFactory Inside Program.cs
Full source code here. Over the past week I have written a few articles about HttpClientFactory and dependency injection in .NET Core 2.1. There is one scenario I didn’t deal with – calling a...
View ArticleCalling Generic Methods Using Reflection
Full source code here. Accessing generic methods by reflection is not easy. A while ago I needed to do just that and found relatively little information out there. So I dug in a figured it out for...
View ArticleTesting Your Code When Using Polly
Full source code here. When developing an application with Polly you will also probably want to write some unit tests. Here are the scenarios I test for – 1. How my code behaves when the policy throws...
View ArticleSelectively Caching a HttpResponseMessage with Polly – caching series 1/3
Full source code here. When I give talks on Polly I show how to use it in a Web API application that calls another Web Api application. I give a simple example of how to use the cache policy where I...
View ArticleCaching Values Inside HttpResponseMessage with Polly – caching series 2/3
Full source code here. In this, the second of three posts on caching in Polly, I will show how to cache the values returned inside a HttpResponseMessage as opposed to caching the response with all its...
View ArticleSelectively Caching Values Inside HttpResponseMessage with Polly – caching...
Full source code here. This is the last of three posts on caching with Polly. The first showed how to selectively cache HttpResponseMessages based on the status code of the response. The second showed...
View Article