OrionInject 2.0.4

dotnet add package OrionInject --version 2.0.4
                    
NuGet\Install-Package OrionInject -Version 2.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OrionInject" Version="2.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OrionInject" Version="2.0.4" />
                    
Directory.Packages.props
<PackageReference Include="OrionInject" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OrionInject --version 2.0.4
                    
#r "nuget: OrionInject, 2.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OrionInject@2.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OrionInject&version=2.0.4
                    
Install as a Cake Addin
#tool nuget:?package=OrionInject&version=2.0.4
                    
Install as a Cake Tool

OrionInject 🚀

A lightweight, high-performance Dependency Injection (DI) container for .NET, designed with:

  • 🔁 Lifetime management
  • 🧩 Constructor injection
  • 🧵 Thread safety
  • 🎯 Explicit constructor selection

✨ Features

  • Multiple Lifetimes: Singleton, Transient, and (soon) Scoped
  • Thread-Safe Resolution: Safe for multi-threaded environments
  • Constructor Injection: Automatic resolution via constructors
  • Explicit Constructor Selection: Use [Inject] to mark preferred constructor
  • Circular Dependency Detection: Prevents infinite loops
  • Open Generics Support (planned)
  • Minimal Overhead: No runtime reflection-heavy magic

📦 Installation

dotnet add package OrionInject

Or manually in .csproj:

<PackageReference Include="OrionInject" Version="x.y.z" />

🚀 Quick Start

1. Define Services

public interface IMessageService
{
    void Send(string message);
}

public class EmailMessageService : IMessageService
{
    public void Send(string message) => Console.WriteLine($"Email sent: {message}");
}

2. Register Services

var container = new OrionContainer();
container.Register<IMessageService, EmailMessageService>(Lifetime.Singleton);

3. Resolve and Use

var service = container.Get<IMessageService>();
service.Send("Hello from OrionInject!");

🎯 Advanced Usage

Explicit Constructor Selection

public class ReportGenerator
{
    private readonly IMessageService _messageService;
    private readonly ILogger _logger;

    [Inject] // OrionInject will use this constructor
    public ReportGenerator(IMessageService messageService)
    {
        _messageService = messageService;
        _logger = new ConsoleLogger();
    }

    public ReportGenerator(IMessageService messageService, ILogger logger)
    {
        _messageService = messageService;
        _logger = logger;
    }
}

Circular Dependency Detection

public class ServiceA { public ServiceA(ServiceB b) { } }
public class ServiceB { public ServiceB(ServiceA a) { } }

container.Register<ServiceA>(Lifetime.Transient);
container.Register<ServiceB>(Lifetime.Transient);

// Throws: CircularDependencyException
var a = container.Get<ServiceA>();

Thread-Safe Singleton

container.Register<HeavyService>(Lifetime.Singleton);

Parallel.For(0, 10, _ =>
{
    var instance = container.Get<HeavyService>();
    Console.WriteLine(instance.GetHashCode());
});

🛠 Best Practices

  • Use Singleton for stateless, shared services
  • Use Transient for lightweight, short-lived objects
  • Prefer constructor injection over service locators
  • Use [Inject] to guide constructor selection when multiple exist
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.4 132 9/8/2025
2.0.1 68 9/6/2025
1.2.2 1,470 11/4/2017

Key Features
           Multiple Lifetimes – Built‑in support for Singleton and Transient lifetimes, with Scoped on the roadmap.

           Thread‑Safe Resolution – Safe to use in multi‑threaded environments without extra locking code.

           Constructor Injection – Automatically resolves dependencies via the most appropriate constructor.

           Explicit Constructor Selection – Use the [Inject] attribute to choose exactly which constructor OrionInject should use.

           Circular Dependency Detection – Prevents infinite loops by detecting and rejecting circular references at resolution time.

           Minimal Overhead – Lightweight core with no heavy runtime reflection or hidden magic.

           Extensible Design – Easy to extend with custom lifetime managers, registration patterns, or resolution strategies.

           Clear Error Messages – Developer‑friendly exceptions that make debugging painless.

           Open Generics Support (planned) – Register and resolve generic types without boilerplate.

           Property Injection (planned) – Optional injection into public settable properties.

           Attribute‑Driven Configuration – Fine‑tune behavior without complex configuration files.

           Production‑Ready – Mature enough for real‑world applications, yet simple enough for small projects.