-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleModuleOptions.cs
More file actions
66 lines (55 loc) · 2.27 KB
/
SimpleModuleOptions.cs
File metadata and controls
66 lines (55 loc) · 2.27 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using Microsoft.Extensions.DependencyInjection;
using SimpleModule.Core;
using SimpleModule.Database;
namespace SimpleModule.Hosting;
public class SimpleModuleOptions
{
private readonly List<Action<IServiceCollection>> _moduleOptionsActions = [];
public bool EnableSwagger { get; set; } = true;
public bool EnableHealthChecks { get; set; } = true;
public bool EnableDevTools { get; set; } = true;
/// <summary>
/// Logs a warning at startup for every SimpleModule contract interface
/// (e.g. <c>IUsersContracts</c>) that is in the assembly graph but has no
/// registered implementation — the typical signal that a peer module's
/// package is missing.
/// Defaults to true in non-Production environments and false otherwise so
/// production logs aren't polluted by intentionally-absent peers.
/// </summary>
public bool ValidateModuleGraph { get; set; } = true;
/// <summary>
/// Content Security Policy overrides. Modules can append extra origins for
/// directives like <c>connect-src</c>, <c>img-src</c>, etc.
/// </summary>
public CspOptions Csp { get; } = new();
/// <summary>
/// The detected database provider, set during startup validation.
/// </summary>
internal DatabaseProvider DatabaseProvider { get; set; }
/// <summary>
/// Configures options for a module. Called by generated Configure{Module}() extension methods.
/// </summary>
public SimpleModuleOptions ConfigureModule<TOptions>(Action<TOptions> configure)
where TOptions : class, IModuleOptions
{
_moduleOptionsActions.Add(services => services.Configure(configure));
return this;
}
/// <summary>
/// Registers default options and applies user overrides. Called by generated code.
/// </summary>
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public void ApplyModuleOptions(
IServiceCollection services,
Action<IServiceCollection> registerDefaults
)
{
// Register IOptions<T> defaults for all discovered options classes
registerDefaults(services);
// Apply user-provided overrides
foreach (var action in _moduleOptionsActions)
{
action(services);
}
}
}