-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
ConfigureOptions.cs
39 lines (34 loc) · 1.19 KB
/
ConfigureOptions.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
37
38
39
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
namespace Microsoft.Extensions.Options
{
/// <summary>
/// Implementation of <see cref="IConfigureOptions{TOptions}"/>.
/// </summary>
/// <typeparam name="TOptions">Options type being configured.</typeparam>
public class ConfigureOptions<TOptions> : IConfigureOptions<TOptions> where TOptions : class
{
/// <summary>
/// Constructor.
/// </summary>
/// <param name="action">The action to register.</param>
public ConfigureOptions(Action<TOptions>? action)
{
Action = action;
}
/// <summary>
/// The configuration action.
/// </summary>
public Action<TOptions>? Action { get; }
/// <summary>
/// Invokes the registered configure <see cref="Action"/>.
/// </summary>
/// <param name="options">The options instance to configure.</param>
public virtual void Configure(TOptions options)
{
ThrowHelper.ThrowIfNull(options);
Action?.Invoke(options);
}
}
}