Skip to content

Needlr

Needlr

Opinionated fluent dependency injection for .NET with source generation.

CI Coverage NuGet

What is Needlr?

Needlr is a source-generation-first dependency injection library for .NET that provides automatic service registration through a simple, discoverable API. It's designed to minimize boilerplate code by automatically registering types from scanned assemblies.

Source Generation First

Needlr prioritizes compile-time source generation for AOT compatibility and optimal performance. Both source-gen (.UsingSourceGen()) and reflection (.UsingReflection()) require explicit opt-in—source-gen is recommended for most scenarios.

Features

  • Source Generation First - Compile-time type discovery for AOT/trimming compatibility
  • Automatic Service Discovery - Automatically registers services from assemblies using conventions
  • Fluent API - Chain-able configuration methods for clean, readable setup
  • ASP.NET Core Integration - Seamless web application creation and configuration
  • Plugin System - Extensible architecture for modular applications
  • Decorator Pattern Support - Automatic decorator wiring with [DecoratorFor<T>] attribute
  • Analyzers & Diagnostics - Catch DI issues at compile-time, not runtime

Quick Start

Installation

See the Getting Started guide for full package requirements. Quick overview:

<PackageReference Include="NexusLabs.Needlr.Injection" />
<PackageReference Include="NexusLabs.Needlr.Injection.SourceGen" />
<PackageReference Include="NexusLabs.Needlr.Generators" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="NexusLabs.Needlr.Generators.Attributes" />
<!-- For ASP.NET Core: NexusLabs.Needlr.AspNet -->
<PackageReference Include="NexusLabs.Needlr.Injection" />
<PackageReference Include="NexusLabs.Needlr.Injection.Reflection" />
<!-- For ASP.NET Core: NexusLabs.Needlr.AspNet -->
using NexusLabs.Needlr.AspNet;
using NexusLabs.Needlr.Injection;
using NexusLabs.Needlr.Injection.SourceGen;

var app = new Syringe()
    .UsingSourceGen()
    .CreateWebApplication(args);

app.Run();

Reflection

using NexusLabs.Needlr.AspNet;
using NexusLabs.Needlr.Injection;
using NexusLabs.Needlr.Injection.Reflection;

var app = new Syringe()
    .UsingReflection()
    .CreateWebApplication(args);

app.Run();

Next Steps

  • Getting Started


    Step-by-step guide to set up Needlr in your project

    Getting Started

  • Core Concepts


    Understand the architecture and design principles

    Core Concepts

  • Features


    Explore hosted services, keyed services, options, and more

    Hosted Services

  • Analyzers


    Compile-time diagnostics to catch DI issues early

    Analyzers