A extremely fast ioc container for high performance applications
Func<T>
Lazy<T>
Expression<Func<T>>
IEnumerable<T>
IReadOnlyCollection<T>
IReadOnlyList<T>
T[]
List<T>
ICollection<T>
IList<T>
HashSet<T>
ISet<T>
With(DisposeBehavior)
or adding the lifetimes you want to auto dispose to SingularitySettings.AutoDisposeLifetimes
.WithFinalizer(Action<TInstance>)
method.Singularity
can be installed through nuget. The packages that are available can be found in the nuget section
Its easy to setup a container and request a instance:
var container = new Container(builder =>
{
builder.Register<ITestService10, TestService10>();
});
var instance = container.GetInstance<ITestService10>();
However Singularity
can do much more than this simple example. You can request the instance with different wrapper types such as Lazy<T>
:
var lazyInstance = container.GetInstance<Lazy<ITestService10>>();
Or you can request the factory to create the instance:
var factory = container.GetInstance<Func<ITestService10>>();
You can even request the expression itself:
var instanceExpression = container.GetInstance<Expression<Func<ITestService10>>>();
Ofcourse its possible to combine these with for instance a collection type such as IEnumerable<T> or IReadOnlyList<T>:
var instanceExpressions = container.GetInstance<IReadOnlyList<Expression<Func<IPlugin>>>>(); //Returns all expressions for IPlugin registrations
Advanced scenarios such as open generics are also supported.
More info about Singularity
can be found on the documentation website which can be found here.
The code used in the benchmark can be found here
BenchmarkDotNet=v0.12.0, OS=Windows 10.0.18363
AMD Ryzen 9 3900X, 1 CPU, 24 logical and 12 physical cores
.NET Core SDK=3.1.200
[Host] : .NET Core 3.1.2 (CoreCLR 4.700.20.6602, CoreFX 4.700.20.6702), X64 RyuJIT
LegacyJitX64 : .NET Framework 4.8 (4.8.4150.0), X64 RyuJIT
RyuJitX64 : .NET Core 2.1.16 (CoreCLR 4.6.28516.03, CoreFX 4.6.28516.10), X64 RyuJIT
Platform=X64 IterationTime=1.0000 s
| Method | Job | Jit | Runtime | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
|---------- |------------- |---------- |-------------- |--------------:|------------:|------------:|-------:|-------:|------:|----------:|
| Singleton | LegacyJitX64 | LegacyJit | .NET 4.7.2 | 10.539 ns | 0.1156 ns | 0.1082 ns | - | - | - | - |
| Transient | LegacyJitX64 | LegacyJit | .NET 4.7.2 | 15.095 ns | 0.0562 ns | 0.0525 ns | 0.0145 | - | - | 24 B |
| Combined | LegacyJitX64 | LegacyJit | .NET 4.7.2 | 20.722 ns | 0.0707 ns | 0.0552 ns | 0.0338 | - | - | 56 B |
| Complex | LegacyJitX64 | LegacyJit | .NET 4.7.2 | 27.218 ns | 0.2894 ns | 0.2566 ns | 0.0580 | - | - | 96 B |
| Singleton | RyuJitX64 | RyuJit | .NET Core 2.1 | 9.569 ns | 0.0634 ns | 0.0593 ns | - | - | - | - |
| Transient | RyuJitX64 | RyuJit | .NET Core 2.1 | 14.755 ns | 0.1025 ns | 0.0959 ns | 0.0145 | - | - | 24 B |
| Combined | RyuJitX64 | RyuJit | .NET Core 2.1 | 22.506 ns | 0.3656 ns | 0.3420 ns | 0.0337 | - | - | 56 B |
| Complex | RyuJitX64 | RyuJit | .NET Core 2.1 | 26.756 ns | 0.3521 ns | 0.3294 ns | 0.0578 | - | - | 96 B |
| Singleton | RyuJitX64 | RyuJit | .NET Core 3.1 | 12.167 ns | 0.1213 ns | 0.1135 ns | - | - | - | - |
| Transient | RyuJitX64 | RyuJit | .NET Core 3.1 | 14.461 ns | 0.0698 ns | 0.0653 ns | 0.0029 | - | - | 24 B |
| Combined | RyuJitX64 | RyuJit | .NET Core 3.1 | 20.933 ns | 0.2406 ns | 0.2251 ns | 0.0067 | - | - | 56 B |
| Complex | RyuJitX64 | RyuJit | .NET Core 3.1 | 24.196 ns | 0.1059 ns | 0.0991 ns | 0.0115 | - | - | 96 B |
Library | Version |
---|---|
Singularity | |
Singularity.Duality.core | |
Singularity.Microsoft.DependencyInjection | |
Singularity.AspNetCore.Hosting | |
Singularity.AspNetCore.MVC |
Paypal |
---|
Licensed under LGPL.