< Summary

Information
Class: NexusLabs.Needlr.RegisterAsAttribute<T>
Assembly: NexusLabs.Needlr
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr/RegisterAsAttribute.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 1
Coverable lines: 1
Total lines: 57
Line coverage: 0%
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_InterfaceType()100%210%

File(s)

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

#LineLine coverage
 1namespace NexusLabs.Needlr;
 2
 3/// <summary>
 4/// Specifies that the decorated class should only be registered as the specified interface type,
 5/// rather than all interfaces it implements.
 6/// </summary>
 7/// <typeparam name="TInterface">
 8/// The interface type to register as. Must be an interface implemented by the decorated class.
 9/// </typeparam>
 10/// <remarks>
 11/// <para>
 12/// By default, Needlr registers a class as all non-system interfaces it implements.
 13/// Use this attribute when you want explicit control over which interface(s) are publicly
 14/// resolvable from the container.
 15/// </para>
 16/// <para>
 17/// When this attribute is present, the class will ONLY be registered as the specified interface(s)
 18/// and as itself (the concrete type). Other implemented interfaces will not be registered.
 19/// </para>
 20/// <para>
 21/// Multiple [RegisterAs&lt;T&gt;] attributes can be applied to register the class as multiple
 22/// specific interfaces while still excluding others.
 23/// </para>
 24/// </remarks>
 25/// <example>
 26/// <code>
 27/// public interface IReader { string Read(); }
 28/// public interface IWriter { void Write(string data); }
 29/// public interface ILogger { void Log(string message); }
 30///
 31/// // Only registered as IReader - not as IWriter or ILogger
 32/// [RegisterAs&lt;IReader&gt;]
 33/// public class FileService : IReader, IWriter, ILogger
 34/// {
 35///     public string Read() => "data";
 36///     public void Write(string data) { }
 37///     public void Log(string message) { }
 38/// }
 39///
 40/// // Register as multiple specific interfaces
 41/// [RegisterAs&lt;IReader&gt;]
 42/// [RegisterAs&lt;IWriter&gt;]
 43/// public class DualService : IReader, IWriter, ILogger
 44/// {
 45///     // Registered as IReader and IWriter, but NOT as ILogger
 46/// }
 47/// </code>
 48/// </example>
 49[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
 50public sealed class RegisterAsAttribute<TInterface> : Attribute
 51    where TInterface : class
 52{
 53    /// <summary>
 54    /// Gets the interface type that the class should be registered as.
 55    /// </summary>
 056    public Type InterfaceType => typeof(TInterface);
 57}

Methods/Properties

get_InterfaceType()