| | | 1 | | namespace NexusLabs.Needlr; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Builder for creating <see cref="VerificationOptions"/> with a fluent API. |
| | | 5 | | /// </summary> |
| | | 6 | | public sealed class VerificationOptionsBuilder |
| | | 7 | | { |
| | 2 | 8 | | private VerificationBehavior _lifetimeMismatchBehavior = VerificationBehavior.Warn; |
| | 2 | 9 | | private VerificationBehavior _circularDependencyBehavior = VerificationBehavior.Throw; |
| | | 10 | | private Action<VerificationIssue>? _issueReporter; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Sets the behavior when lifetime mismatches are detected. |
| | | 14 | | /// </summary> |
| | | 15 | | public VerificationOptionsBuilder OnLifetimeMismatch(VerificationBehavior behavior) |
| | | 16 | | { |
| | 2 | 17 | | _lifetimeMismatchBehavior = behavior; |
| | 2 | 18 | | return this; |
| | | 19 | | } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Sets the behavior when circular dependencies are detected. |
| | | 23 | | /// </summary> |
| | | 24 | | public VerificationOptionsBuilder OnCircularDependency(VerificationBehavior behavior) |
| | | 25 | | { |
| | 1 | 26 | | _circularDependencyBehavior = behavior; |
| | 1 | 27 | | return this; |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Sets a custom reporter for verification issues. |
| | | 32 | | /// </summary> |
| | | 33 | | public VerificationOptionsBuilder ReportIssuesTo(Action<VerificationIssue> reporter) |
| | | 34 | | { |
| | 1 | 35 | | _issueReporter = reporter; |
| | 1 | 36 | | return this; |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Throws on any verification issue. |
| | | 41 | | /// </summary> |
| | | 42 | | public VerificationOptionsBuilder Strict() |
| | | 43 | | { |
| | 0 | 44 | | _lifetimeMismatchBehavior = VerificationBehavior.Throw; |
| | 0 | 45 | | _circularDependencyBehavior = VerificationBehavior.Throw; |
| | 0 | 46 | | return this; |
| | | 47 | | } |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Disables all verification. |
| | | 51 | | /// </summary> |
| | | 52 | | public VerificationOptionsBuilder Disabled() |
| | | 53 | | { |
| | 0 | 54 | | _lifetimeMismatchBehavior = VerificationBehavior.Silent; |
| | 0 | 55 | | _circularDependencyBehavior = VerificationBehavior.Silent; |
| | 0 | 56 | | return this; |
| | | 57 | | } |
| | | 58 | | |
| | | 59 | | /// <summary> |
| | | 60 | | /// Builds the configured <see cref="VerificationOptions"/>. |
| | | 61 | | /// </summary> |
| | 2 | 62 | | public VerificationOptions Build() => new() |
| | 2 | 63 | | { |
| | 2 | 64 | | LifetimeMismatchBehavior = _lifetimeMismatchBehavior, |
| | 2 | 65 | | CircularDependencyBehavior = _circularDependencyBehavior, |
| | 2 | 66 | | IssueReporter = _issueReporter |
| | 2 | 67 | | }; |
| | | 68 | | } |