Easy way to create a C# lambda expression from a string (with Roslyn)

I’ve worked on quite a lot of projects over the years, with many different teams, and one of the questions that keeps coming back to me over and over with a high degree of regularity is how to load a C# lambda from a string - for example from a configuration file.

This is not surprising, because being able to do that can give you a tremendous amount of flexibility in your code, as it would (for the lack of better word) unlock the possibility to alter business logic from the configuration level, without having to recompile and redeploy your application.

Historically, this has been possible but also quite a painful task. Today I wanted to show you a remarkably simple solution to this problem - with the help of the Roslyn compiler Nuget packages.

TypedRouting for ASP.NET Core MVC 2

Today I have released a new version of Strathweb.TypedRouting.AspNetCore. This new version is built as .NET Standard 2.0, and - obviously - finally supports ASP.NET Core MVC 2.

Here is a short summary and some links to help you get started.

[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.

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

Last week, together with [Bernhard][1] we released version [0.16 of dotnet-script][2], 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.

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.

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.

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.

Strathweb TypedRouting AspNetCore 1.1.0 released!

Today I have released the 1.1.0 version of Typed Routing project. I encourage you to try this if you like to have your routes centrally configured, rather than stored in attributes at action level.

You can install it from NuGet using the Strathweb.TypedRouting.AspNetCore package name. Here is what’s new in this release.

dotnet-script 0.11 out – with inline Nuget support

Yesterday I released, thanks to the great help of Bernhard - version 0.11 of dotnet-script, the C# script runner for .NET Core.

It is the biggest release yet - with the highlight feature being the ability to use inline Nuget packages.

Here is the overview of what’s in there.

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.

About


Hi! I'm Filip W., a cloud architect from Zürich 🇨🇭. I like Toronto Maple Leafs 🇨🇦, Rancid and quantum computing. Oh, and I love the Lowlands 🏴󠁧󠁢󠁳󠁣󠁴󠁿.

You can find me on Github and on Mastodon.

My Introduction to Quantum Computing with Q# and QDK book
Microsoft MVP