| | | 1 | | namespace AsiBackbone.AspNetCore.DependencyInjection; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Provides configuration options for ASP.NET Core host integration. |
| | | 5 | | /// </summary> |
| | | 6 | | public sealed class AsiBackboneAspNetCoreOptions |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Gets the default header names checked for correlation identifier propagation. |
| | | 10 | | /// </summary> |
| | 94 | 11 | | public static IReadOnlyList<string> DefaultCorrelationIdHeaderNames { get; } = |
| | 3 | 12 | | [ |
| | 3 | 13 | | "X-Correlation-ID", |
| | 3 | 14 | | "X-Request-ID", |
| | 3 | 15 | | "Traceparent", |
| | 3 | 16 | | ]; |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Gets or sets a value indicating whether HTTP route values may be included by request-context adapters. |
| | | 20 | | /// </summary> |
| | 139 | 21 | | public bool IncludeRouteValues { get; set; } = true; |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Gets or sets a value indicating whether endpoint metadata may be inspected by request-context adapters. |
| | | 25 | | /// </summary> |
| | | 26 | | public bool IncludeEndpointMetadata |
| | | 27 | | { |
| | 10 | 28 | | get => IncludeEndpointDisplayName || IncludeRoutePattern; |
| | | 29 | | set |
| | | 30 | | { |
| | 10 | 31 | | IncludeEndpointDisplayName = value; |
| | 10 | 32 | | IncludeRoutePattern = value; |
| | 10 | 33 | | } |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Gets or sets a value indicating whether the HTTP method may be included as safe audit metadata. |
| | | 38 | | /// </summary> |
| | 139 | 39 | | public bool IncludeRequestMethod { get; set; } = true; |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Gets or sets a value indicating whether the HTTP path may be included as safe audit metadata. |
| | | 43 | | /// </summary> |
| | 45 | 44 | | public bool IncludeRequestPath { get; set; } |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// Gets or sets a value indicating whether endpoint display names may be included as safe audit metadata. |
| | | 48 | | /// </summary> |
| | 159 | 49 | | public bool IncludeEndpointDisplayName { get; set; } = true; |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Gets or sets a value indicating whether endpoint route patterns may be included as safe audit metadata. |
| | | 53 | | /// </summary> |
| | 153 | 54 | | public bool IncludeRoutePattern { get; set; } = true; |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Gets or sets a value indicating whether the ASP.NET Core trace identifier is used as the correlation identifier |
| | | 58 | | /// when no configured correlation header is present. |
| | | 59 | | /// </summary> |
| | 133 | 60 | | public bool UseHttpContextTraceIdentifierAsCorrelationId { get; set; } = true; |
| | | 61 | | |
| | | 62 | | /// <summary> |
| | | 63 | | /// Gets or sets the primary HTTP header name preferred for correlation identifier propagation. |
| | | 64 | | /// </summary> |
| | | 65 | | public string CorrelationIdHeaderName |
| | | 66 | | { |
| | 8 | 67 | | get => CorrelationIdHeaderNames.FirstOrDefault() ?? string.Empty; |
| | 12 | 68 | | set => CorrelationIdHeaderNames = [value]; |
| | | 69 | | } |
| | | 70 | | |
| | | 71 | | /// <summary> |
| | | 72 | | /// Gets or sets the HTTP header names checked for correlation identifier propagation. |
| | | 73 | | /// </summary> |
| | 456 | 74 | | public IList<string> CorrelationIdHeaderNames { get; set; } = [.. DefaultCorrelationIdHeaderNames]; |
| | | 75 | | |
| | | 76 | | /// <summary> |
| | | 77 | | /// Validates the options. |
| | | 78 | | /// </summary> |
| | | 79 | | public void Validate() |
| | | 80 | | { |
| | 97 | 81 | | if (CorrelationIdHeaderNames is null || CorrelationIdHeaderNames.Count == 0 || CorrelationIdHeaderNames.All(stri |
| | | 82 | | { |
| | 12 | 83 | | throw new InvalidOperationException("At least one correlation identifier header name must be configured."); |
| | | 84 | | } |
| | 85 | 85 | | } |
| | | 86 | | } |