< Summary

Information
Class: NexusLabs.Needlr.KeyedAttribute
Assembly: NexusLabs.Needlr
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr/KeyedAttribute.cs
Line coverage
75%
Covered lines: 3
Uncovered lines: 1
Coverable lines: 4
Total lines: 44
Line coverage: 75%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)50%22100%
get_Key()100%210%

File(s)

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

#LineLine coverage
 1namespace NexusLabs.Needlr;
 2
 3/// <summary>
 4/// Marks a class for keyed service registration. The type will be registered
 5/// with the specified service key in addition to its normal registration.
 6/// </summary>
 7/// <remarks>
 8/// <para>
 9/// Use this attribute when you want to register multiple implementations of
 10/// the same interface with different keys, allowing consumers to resolve
 11/// specific implementations using <c>[FromKeyedServices("key")]</c>.
 12/// </para>
 13/// <para>
 14/// Example:
 15/// <code>
 16/// [Keyed("stripe")]
 17/// public class StripeProcessor : IPaymentProcessor { }
 18///
 19/// [Keyed("paypal")]
 20/// public class PayPalProcessor : IPaymentProcessor { }
 21///
 22/// // Consumer resolves specific implementation:
 23/// public class OrderService(
 24///     [FromKeyedServices("stripe")] IPaymentProcessor processor) { }
 25/// </code>
 26/// </para>
 27/// </remarks>
 28[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
 29public sealed class KeyedAttribute : Attribute
 30{
 31    /// <summary>
 32    /// Initializes a new instance of the <see cref="KeyedAttribute"/> class.
 33    /// </summary>
 34    /// <param name="key">The service key for this registration.</param>
 123035    public KeyedAttribute(string key)
 36    {
 123037        Key = key ?? throw new ArgumentNullException(nameof(key));
 123038    }
 39
 40    /// <summary>
 41    /// Gets the service key for this registration.
 42    /// </summary>
 043    public string Key { get; }
 44}

Methods/Properties

.ctor(System.String)
get_Key()