-
Notifications
You must be signed in to change notification settings - Fork 66
/
SettingValidationStartupFilter.cs
36 lines (32 loc) · 1.13 KB
/
SettingValidationStartupFilter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
namespace NetEscapades.Configuration.Validation
{
/// <summary>
/// An <see cref="IStartupFilter"/> that validates <see cref="IValidatable"/> objects are valid on app startup
/// </summary>
public class SettingValidationStartupFilter : IStartupFilter
{
readonly IEnumerable<IValidatable> _validatableObjects;
/// <summary>
/// Create a new instance of <see cref="SettingValidationStartupFilter"/>
/// </summary>
/// <param name="validatableObjects"></param>
public SettingValidationStartupFilter(IEnumerable<IValidatable> validatableObjects)
{
_validatableObjects = validatableObjects;
}
/// <inheritdoc />
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
{
foreach (var validatableObject in _validatableObjects)
{
validatableObject.Validate();
}
//don't alter the configuration
return next;
}
}
}