< Summary

Information
Class: NexusLabs.Needlr.VerificationOptions
Assembly: NexusLabs.Needlr
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr/VerificationOptions.cs
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 102
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_LifetimeMismatchBehavior()100%11100%
get_CircularDependencyBehavior()100%11100%
get_IssueReporter()100%11100%
get_Default()100%11100%
get_Strict()100%11100%
get_Disabled()100%11100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr/VerificationOptions.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2
 3namespace NexusLabs.Needlr;
 4
 5/// <summary>
 6/// Options for controlling container verification behavior.
 7/// </summary>
 8public sealed record VerificationOptions
 9{
 10    /// <summary>
 11    /// Gets or sets the behavior when lifetime mismatches are detected.
 12    /// Default is <see cref="VerificationBehavior.Warn"/>.
 13    /// </summary>
 103014    public VerificationBehavior LifetimeMismatchBehavior { get; init; } = VerificationBehavior.Warn;
 15
 16    /// <summary>
 17    /// Gets or sets the behavior when circular dependencies are detected.
 18    /// Default is <see cref="VerificationBehavior.Throw"/>.
 19    /// </summary>
 51220    public VerificationBehavior CircularDependencyBehavior { get; init; } = VerificationBehavior.Throw;
 21
 22    /// <summary>
 23    /// Gets or sets a callback for reporting verification issues.
 24    /// If null, issues are written to Console.Error.
 25    /// </summary>
 1926    public Action<VerificationIssue>? IssueReporter { get; init; }
 27
 28    /// <summary>
 29    /// Default verification options - warns on lifetime mismatches, throws on circular dependencies.
 30    /// </summary>
 48931    public static VerificationOptions Default => new();
 32
 33    /// <summary>
 34    /// Strict verification options - throws on any verification issue.
 35    /// </summary>
 636    public static VerificationOptions Strict => new()
 637    {
 638        LifetimeMismatchBehavior = VerificationBehavior.Throw,
 639        CircularDependencyBehavior = VerificationBehavior.Throw
 640    };
 41
 42    /// <summary>
 43    /// Disabled verification - no checks performed.
 44    /// </summary>
 145    public static VerificationOptions Disabled => new()
 146    {
 147        LifetimeMismatchBehavior = VerificationBehavior.Silent,
 148        CircularDependencyBehavior = VerificationBehavior.Silent
 149    };
 50}
 51
 52/// <summary>
 53/// Specifies the behavior when a verification issue is detected.
 54/// </summary>
 55public enum VerificationBehavior
 56{
 57    /// <summary>
 58    /// Ignore the issue silently.
 59    /// </summary>
 60    Silent = 0,
 61
 62    /// <summary>
 63    /// Log a warning but continue.
 64    /// </summary>
 65    Warn = 1,
 66
 67    /// <summary>
 68    /// Throw an exception to prevent the application from starting.
 69    /// </summary>
 70    Throw = 2
 71}
 72
 73/// <summary>
 74/// Represents a verification issue detected during container analysis.
 75/// </summary>
 76public sealed record VerificationIssue(
 77    VerificationIssueType Type,
 78    string Message,
 79    string DetailedMessage,
 80    VerificationBehavior ConfiguredBehavior)
 81{
 82    /// <summary>
 83    /// Gets the service types involved in this issue.
 84    /// </summary>
 85    public IReadOnlyList<Type> InvolvedTypes { get; init; } = [];
 86}
 87
 88/// <summary>
 89/// The type of verification issue detected.
 90/// </summary>
 91public enum VerificationIssueType
 92{
 93    /// <summary>
 94    /// A longer-lived service depends on a shorter-lived service.
 95    /// </summary>
 96    LifetimeMismatch,
 97
 98    /// <summary>
 99    /// A circular dependency was detected in the dependency graph.
 100    /// </summary>
 101    CircularDependency
 102}