I noticed that the new init properties in C# version 9 seem to bind when used in strongly typed option classes (Options Pattern).
In other words, this works:
class SomeSettings
{
public string FirstSetting { get; init; }
public bool SecondSetting { get; init; }
}
...
configuration.GetSection(nameof(SomeSettings)).Get<SomeSettings>();
But are there any potential 'gotchas' or limitations we should be aware of? (When used either with direct binding, or injected as IOptions<> with Configure().)
Admittedly, my motivation is that I'm thinking about binding and registering these instances directly at configuration time as singletons, without the pesky IOptions<> wrapper. The only reason I haven't done so far was the mutability of the properties, but init seems to solve that.