OrionInject 2.0.1

dotnet add package OrionInject --version 2.0.1
                    
NuGet\Install-Package OrionInject -Version 2.0.1
                    
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.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OrionInject" Version="2.0.1" />
                    
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.1
                    
#r "nuget: OrionInject, 2.0.1"
                    
#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.1
                    
#: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.1
                    
Install as a Cake Addin
#tool nuget:?package=OrionInject&version=2.0.1
                    
Install as a Cake Tool

OrionInject 🚀

A lightweight, high-performance Dependency Injection (DI) container for .NET, built with lifetime management, constructor injection, thread safety, and explicit constructor selection in mind.


✨ Features

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

📦 Installation

dotnet add package OrionInject

Or add the reference manually in your .csproj:

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

🚀 Quick Start

1. Define Your 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.Resolve<IMessageService>();
service.Send("Hello from OrionInject!");

🎯 Advanced Examples

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.Resolve<ServiceA>();

Thread-Safe Singleton

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

// Safe to resolve from multiple threads
Parallel.For(0, 10, _ =>
{
    var instance = container.Resolve<HeavyService>();
    Console.WriteLine(instance.GetHashCode());
});

🛠 Tips & Best Practices

  • Use Singleton for stateless, shared services.
  • Use Transient for short-lived, lightweight objects.
  • Mark your preferred constructor with [Inject] when multiple exist.
  • Avoid service locators — prefer constructor injection for clarity.
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.1 0 9/6/2025
1.2.2 1,408 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.