feat: upgrade application to .NET 10
All checks were successful
Caddy Manager CI build / docker (push) Successful in 6m37s
All checks were successful
Caddy Manager CI build / docker (push) Successful in 6m37s
Preserve configuration defaults with the .NET 10 binder and update dependencies, Docker builds, CI, and test tooling.
This commit is contained in:
@@ -5,19 +5,19 @@
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NetCore.AutoRegisterDi" Version="2.2.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="10.0.10" />
|
||||
<PackageReference Include="Docker.DotNet" Version="3.125.15" />
|
||||
<PackageReference Include="Humanizer" Version="3.0.0-beta.96" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
|
||||
<PackageReference Include="Humanizer" Version="3.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -19,6 +19,18 @@ public class ConfigurationsService(IConfiguration configuration) : IConfiguratio
|
||||
else if (section.EndsWith("Configuration"))
|
||||
section = section[..^"Configuration".Length];
|
||||
|
||||
return configuration.GetSection(section).Get<T>() ?? Activator.CreateInstance<T>();
|
||||
var result = configuration.GetSection(section).Get<T>();
|
||||
var defaults = Activator.CreateInstance<T>();
|
||||
|
||||
if (result is null) return defaults;
|
||||
|
||||
// The .NET 10 binder writes nulls over property initialisers, so put the defaults back
|
||||
foreach (var property in typeof(T).GetProperties())
|
||||
{
|
||||
if (property is { CanRead: true, CanWrite: true } && property.GetValue(result) is null)
|
||||
property.SetValue(result, property.GetValue(defaults));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user