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