Skip to content

DoNotInjectAttribute

NexusLabs.Needlr

NexusLabs.Needlr

DoNotInjectAttribute Class

Prevents a class or interface from being injected as a dependency by Needlr. Types decorated with this attribute are discovered but excluded from service collection registration.

public sealed class DoNotInjectAttribute : System.Attribute

Inheritance System.Object 🡒 System.Attribute 🡒 DoNotInjectAttribute

Example

// This interface is used as a constraint but should never be resolved from the container
[DoNotInject]
public interface IInternalMarker
{
}

Remarks

Use [DoNotInject] when a type should never appear as a resolvable service — for example, infrastructure base classes, marker interfaces, or types that are only used as generic constraints.

Unlike DoNotAutoRegisterAttribute, which signals "register me some other way", [DoNotInject] signals "this type is not a DI service at all".