I have a console application that uses the .NET Generic Host for reading settings and for dependeny injection.
How can I configure which library is used for parsing the JSON configuraton files (appsettings.json
)? I'd like to use Newtonsoft Json.NET instead of the default (System.Text.Json
).
Background: my settings files have BigInteger
values that are handled quite well by Newtonsoft, but fail to load with the default.
Note that this is explicitly not about ASP.NET but a plain console application. It is extremely difficult to find something applying to a simple console app use case because everything googleable is about ASP.NET.
The code setting up the host currently looks like this:
Host
.CreateDefaultBuilder()
.ConfigureLogging(...)
.ConfigureServices(...)
.UseConsoleLifetime()
.Build()
.StartAsync();
Somewhere in there surely is the place to hook up the Newtonsoft JSON parser.
(.NET 6)