Skip to content

ScopedAttribute

NexusLabs.Needlr

NexusLabs.Needlr

ScopedAttribute Class

Specifies that the decorated class should be registered with \<b>Scoped\</b> lifetime. Scoped services are created once per scope — for example, once per HTTP request in ASP.NET Core.

public sealed class ScopedAttribute : System.Attribute

Inheritance System.Object 🡒 System.Attribute 🡒 ScopedAttribute

Example

[Scoped]
public class OrderRepository : IOrderRepository
{
    // Created once per HTTP request / DI scope
}

Remarks

Use [Scoped] when a service must share state across multiple calls within the same logical operation (e.g., a request), but must not be shared across operations.

Without this attribute, Needlr registers classes as Singleton by default. Apply [Scoped] to override that default.