[Required] and [BindRequired] in ASP.NET Core MVC

When controlling the binding behavior of models in ASP.NET Core MVC applications, it is very common to perform some validation on them. For that, data annotations are a perfect tool.

One of the most typical use cases of data annotations is to ensure that a value of a certain property has been provided by the caller of the API – and this, historically (in “classic” ASP.NET MVC), has been controlled by RequiredAttribute. The attribute can still be used in ASP.NET Core MVC, but there is also a new one – BindRequiredAttribute.

Let’s have a look at the subtle differences between them.

Continue Reading

C# REPL for .NET Core 2.0 and #load support from Nuget – dotnet-script 0.16 is out!

Last week, together with Bernhard we released version 0.16 of dotnet-script, the .NET Core 2.0 C# script runner. I’d like to summarize the new features in this short blog post – as there are two highlights of this release – which we are very excited about!

The project now offers a C# REPL (interactive mode) which can be access when launching dotnet-script without any arguments. All the features of scripting are supported in the interactive mode, including support for adding Nuget references via #r “nuget: {package}”.

The second large feature is support for #load “nuget: {package}”, which works similar to its #r counterpart, except not for assemblies but for referencing CSX files from Nuget.

Continue Reading

C# Script Runner for .NET Core 2.0!

As you may have read on this blog before, together with Bernhard, we have been working on a .NET Core and .NET CLI C# script runner, called dotnet-script, for a while now. Today I have a big announcement to make – we have recently released .NET Core 2.0 and .NET Standard 2.0 support!

These changes are part of 0.14.0 release that came out 3 weeks ago. We didn’t want to promote it that much, because – as it’s normally the case with .NET Core related stuff – the accompanying tooling wasn’t ready. In other words, there was no robust language services or intellisense story for writing .NET Core 2.0 scripts.

However, we are now ready with OmniSharp tooling too, which means you can enjoy C# scripting on .NET Core 2.0 in VS Code as long as you install the latest beta release of C# for VS Code. In parallel, we also already released a 0.15.0 version of dotnet-script.

Here is how to get started and a summary of what is new in 0.14.0 and 0.15.0.

Continue Reading

Self-issuing an IdentityServer4 token in an IdentityServer4 service

When building logic around the IdentityServer4 extensibility points, it is sometimes necessary to dynamically issue a token, with which your code can then call some external endpoints or dependencies.

Turns out that rather than round-tripping back to same IdentityServer4 instance over the network to get that token, there is a more efficient and quicker way to do it. Let’s have a look.

Continue Reading

Solution-wide Nuget package handling in .NET SDK-based projects

In this blog post I’d like to show you a very simple technique for ensuring all your Nuget packages across all the projects in a solution have the same version. Such package management improvement introduced recently into the OmniSharp code by one and only Dustin Campbell, and I’ve also been using it in some of my projects.

If your solution is built around .NET SDK csproj projects, which were introduced in Visual Studio 2017, hopefully this blog post will be useful to you.

Continue Reading

Customizing query string parameter binding in ASP.NET Core MVC

A few years ago I blogged about binding parameters from URI in ASP.NET Web API. One of the examples in that post was how to bind a comma-separated collection passed to your API as a query string parameter.

Technologies change, and we now work with ASP.NET Core (and the MVC Core framework), but problems remain the same – so let’s have a look at how we can customize the way parameters are bound from query string in ASP.NET Core MVC.

Continue Reading

Using MessagePack with ASP.NET Core MVC

Some time ago (actually, almost 5 years ago), I blogged about using MessagePack with ASP.NET Web API in order to improve your API’s efficiency over JSON – both in terms of serialization speed and in message payload size.

That code later made it to the WebApiContrib project, where it was released as an add-on to ASP.NET Web API.

I recently had a thought – since we now have WebApiContrib.Core for ASP.NET Core, why not revisit the idea, and create a MessagePack add-on for that too?

Continue Reading