OrionInject 2.0.1
dotnet add package OrionInject --version 2.0.1
NuGet\Install-Package OrionInject -Version 2.0.1
<PackageReference Include="OrionInject" Version="2.0.1" />
<PackageVersion Include="OrionInject" Version="2.0.1" />
<PackageReference Include="OrionInject" />
paket add OrionInject --version 2.0.1
#r "nuget: OrionInject, 2.0.1"
#:package OrionInject@2.0.1
#addin nuget:?package=OrionInject&version=2.0.1
#tool nuget:?package=OrionInject&version=2.0.1
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
, andScoped
(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 | Versions 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. |
-
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.
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.