Using ASP.NET Core Health Checks With ASP.NET Ful...
Health checks in ASP.NET Core are useful for reporting the health of your ASP.NET Core web application. But, this functionality can’t dir...
.NETHealth checks in ASP.NET Core are useful for reporting the health of your ASP.NET Core web application. But, this functionality can’t dir...
.NETAs I’ve walked through upgrading a number of solutions to target a new version of the .NET Framework, I’ve compiled a list of helpful ste...
.NETWhat is WSL? Windows Subsytsem for Linux (aka WSL) is an excellent tool for running Linux-based binaries natively in Windows. With the i...
WSL git ASP.NET MVCIn development it is common to not want to share everything in our code. Things like usernames, password, links to an api, and more shoul...
Vue.js JavaScript WebpackIn Vue computed properties are a life saver when it comes to being able to add logic to data that we need to use in the UI. We want to ke...
Vue.js JavaScriptUpdated Solution! Thanks for the post!If you don't want to create a web.config, you can also drive this through the <AspNetCoreHo...
asp.net asp.net coreI, Khalid Abuhakmeh, recently wrote about my [Razor Pages first impressions][khalid] and am mostly positive about the addition to the ASP...
asp.net asp.net core razorWe’re in the process of scaffolding out our Microsoft Azure environments using Terraform. While Terraform does an excellent job creating ...
Terraform OSSTL;DR Explicitly using SqlBulkCopy might never cause this problem since mapping is done manually, but NPoco’s usage does automatic map...
NPoco SqlBulkCopyAs you’re building out an API it’s important to keep response times in check. In many cases slowness is due to database calls, web reques...
Benchmarking OSSWe’ve accomplished so much this year thanks to @VueJS that we wanted to give back to the Vue community in some way. Ritter IM is sponsor...
VueJSEgg Fried Rice is a homey dish in China. In this post, I am going to show you my method to make this simple, quick, and delicious dish. E...
Food chinese cuisineAt Ritter Insurance Marketing we utilize Azure Web Apps for hosting many of our web applications. Azure Web Apps is a platform as a servi...
Azure Configuration OSSState management, Redux, Vuex… whatever you want to call it or whatever flavor you use, people have a lot of opinions about it. I’ve writ...
JavaScript VueIf you’re familiar with Vue at all, you’re probably familiar with the v-for. And if you’ve used any other front end frameworks, they each...
JavaScript VueDo you want to save 80% of your bandwidth to your search provider? Do you want to deliver content to your users faster? With this one tr...
Development Elasticsearch DebuggingWe operate in a typical QA -> Production workflow on both our front-end and back-end teams. So, what happnes when your front-end is in...
Development JavaScript Dev Ops Vue Vue.js JekyllIf you’re not familiar, or just haven’t used Sass maps, here’s your chance to dive in. Our latest static site was built on Jekyll using ...
sassIn JavaScript, we are always working with different data types to send to the API or display on the UI. Cloning and altering that clone i...
JavaScriptC# being an Object Oriented Programming (OOP) language, we have access to inheritance. Like any feature of a programming language, you sh...
csharp bugsAt Ritter Insurance Marketing, we continue to invest heavily in Web APIs primarily built on top of ASP.NET Web API 2. To supplement our APIs, we also make client libraries available to our other applications. These client libraries hold request and response objects that help reduce the duplication across our ecosystem.
As we were building a new endpoint, Cheng Yang, another developer, asked:
Why are some of the primitive types on the request object
nullable
?
In our case, primitives include:
bool
int
double
DateTime
and DateTimeOffset
We build most of our endpoints to accept JSON. The JSON passed in then goes through a model binding process that maps a JSON request into our C# representation. That’s great, but we lose one thing: intent.
For example, take these three JSON requests:
{ }
{ "count" : null }
{ "count" : 0 }
When mapped to this C# object we get something that is logically equivalent:
public class HelloWorldRequest {
public int Count { get;set; }
}
Which results in a Count
value of 0
. The value of our C# request object does not reflect the callers intent.
When we use Nullable<T>
on our request, we get a tri-state property.
This tri-state attribute of Nullable
allows us to respond to the requester with more meaningful validation messages.
- "You forgot to set 'Count' on the request."
- "'0' is an invalid value for 'Count'."
In our previous example, our request would change:
public class HelloWorldRequest {
public int? Count { get;set; }
}
Nullables work for us the majority of the time, but if you want to get advanced, you can hook directly into Web API 2 model binding. We did this for our PATCH
implementation, which you can read in our series entitled “Extending Patch Support For ASP.NET Web API.”]
Requests are the conduit between our requesters and us, and it is important to keep as much fidelity around intent as we possibly can. Nullables on our request objects help due to their tri-state behavior. The practice allows us to respond with more meaningful validation messages, helping our users diagnose and speed up development. In this case, nulls are a good thing.