Skip to content

Commit

Permalink
Validation for appsettings
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Jan 2, 2024
1 parent 69ad372 commit 35126a8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/LinkDotNet.Blog.Web/ApplicationConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using System.ComponentModel.DataAnnotations;

namespace LinkDotNet.Blog.Web;

public sealed record ApplicationConfiguration
{
[Required]
public string BlogName { get; init; }

public string BlogBrandUrl { get; init; }

[Required]
public string ConnectionString { get; init; }

public string DatabaseName { get; init; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.ComponentModel.DataAnnotations;

namespace LinkDotNet.Blog.Web.Authentication.OpenIdConnect;

public sealed record AuthInformation
Expand All @@ -6,12 +8,16 @@ public sealed record AuthInformation

public const string AuthInformationSection = "Authentication";

[Required]
public string Provider { get; set; }

[Required]
public string Domain { get; init; }

[Required]
public string ClientId { get; init; }

[Required]
public string ClientSecret { get; init; }

public string LogoutUri
Expand Down
8 changes: 6 additions & 2 deletions src/LinkDotNet.Blog.Web/ConfigurationExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ private static IServiceCollection AddApplicationConfiguration(this IServiceColle
settings.IsGiscusEnabled = giscusSection.Exists();

config.Bind(settings);
});
})
.ValidateDataAnnotations()
.ValidateOnStart();
return services;
}

Expand All @@ -50,7 +52,9 @@ private static IServiceCollection AddAuthenticationConfigurations(this IServiceC
.Configure<IConfiguration>((settings, config) =>
{
config.GetSection(AuthInformation.AuthInformationSection).Bind(settings);
});
})
.ValidateDataAnnotations()
.ValidateOnStart();
return services;
}

Expand Down

0 comments on commit 35126a8

Please sign in to comment.