Building strongly typed application configuration utility with Roslyn

Awesome: Building strongly typed application configuration utility with Roslyn use Roselyn scripting engine to delegate to an external script filling a strongly typed instance.

The complete code is already very short but all is really made in only 3 lines :

  1. fill a ScriptOptions instance,
  2. creating a CSharpScript and
  3. running it asynchroniously.

For a production use, script error detection must be added and a way to add new references from script itself (and perhaps nuget references).

EDIT: I’ve neglected to follow a link about ConfigR: same needs but some step head. ConfigR use scriptcs on top of Roselyn to provide more possibilities: load sub script, add reference, use predefined packs (nuget packages but more script friendly using MEF) and debugging.

Advertisements

JSON Patch

I don’t know JsonPatch before reading this post from Ben Foster.

It’s a normalized way (RFC 6902) of specifying, in json format, patch to a json document. You write operations for add, removereplace, copy, move and test.

Main use is for reduce http request size (using http PATCH) but I think json is not necessarily the good format when request size matter (I like protobuf but I don’t know if a patch mechanism exist for it).

And in Ben Foster’s blog entry, I also discovers that .Net core already have an aspnet/JsonPatch (available for .Net 4.5.1). It’s easy to use in http server or outside. You creates a JsonPatchDocument with a list of operation, you can add yours then you apply them with a ApplyTo. Json.Net is used internally and we can add a custom IContractResolver.

Source: How to perform partial resource updates with JSON Patch and ASP.NET Core – Ben Foster

IConfiguration in .NetCore

 

A post describing what .Net Core provides for configuration managment: IConfiguration in .NetCore.

You have a hierarchical settings provider architecture able to merge mutiple sources. The only drawback: it’s not possible to strongly typed settings.

Seems pretty interresting. You also have in the box ini files,  command line, environement variables and the ability to ReloadOnChange  for files (through the general Microsoft.Extensions.Primitives.IChangeToken).

Weak documentation and extreme modularity complicate usage (It takes me too long just to find where IChangeToken is) .

This is supposed to be available on .Net 4.5.1 but only in prerelease.