Git Product home page Git Product logo

singularity's Introduction

Singularity

Discord NuGet Badge Build Status Azure DevOps tests (branch) coverage Beerpay

Features

  • Extreme performance, Singularity is one of the fastest if not the fastest dependency injection container out there. Don't believe me? Check out my benchmarks or if you want a second opinion check out the benchmarks that Daniel Palme made here.
  • Clean fluent API.
  • Generic wrappers:
    1. Func<T>
    2. Lazy<T>
    3. Expression<Func<T>>
  • Collection support:
    1. IEnumerable<T>
    2. IReadOnlyCollection<T>
    3. IReadOnlyList
  • Supports open generics.
  • Supports resolving unregistered concrete types.
  • Supports decorators.
  • Supports method and property injection without forcing you to litter attributes all over your code base. All configuration is kept inside the container.
  • Auto dispose, this is off by default but can be turned on with With(DisposeBehavior)or by setting SingularitySettings.AutoDispose to true.
  • Custom finalizers with the WithFinalizer(Action<TInstance>) method.
  • Supports Transient, Singleton and Scope lifetimes.
  • Supports child containers.
  • Clear error messages and fail fast to point you in the right direction as fast as possible.

Getting started

Installation

Singularity can be installed through nuget. The packages that are available can be found in the nuget section

A simple example

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 or IReadOnlyList:

var instanceExpressions = container.GetInstance<IReadOnlyList<Expression<Func<IPlugin>>>>(); //Returns all expressions for IPlugin registrations

Advanced scenarios such as open generics are also supported.

Documentation

More info about Singularity can be found on the documentation website which can be found here.

Other

Benchmarks

The code used in the benchmark can be found here

BenchmarkDotNet=v0.11.4, OS=Windows 10.0.17763.437 (1809/October2018Update/Redstone5)
Intel Core i7-4790K CPU 4.00GHz (Haswell), 1 CPU, 8 logical and 4 physical cores
.NET Core SDK=3.0.100-preview3-010431
  [Host]       : .NET Core 2.1.9 (CoreCLR 4.6.27414.06, CoreFX 4.6.27415.01), 64bit RyuJIT
  LegacyJitX64 : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.3324.0
  RyuJitX64    : .NET Core 2.1.9 (CoreCLR 4.6.27414.06, CoreFX 4.6.27415.01), 64bit RyuJIT

Platform=X64  IterationTime=500.0000 ms

|    Method |          Job |       Jit | Runtime |      Mean |     Error |    StdDev | Gen 0/1k Op | Gen 1/1k Op | Gen 2/1k Op | Allocated Memory/Op |
|---------- |------------- |---------- |-------- |----------:|----------:|----------:|------------:|------------:|------------:|--------------------:|
| Singleton | LegacyJitX64 | LegacyJit |     Clr |  7.700 ns | 0.0722 ns | 0.0675 ns |           - |           - |           - |                   - |
| Transient | LegacyJitX64 | LegacyJit |     Clr | 10.086 ns | 0.0220 ns | 0.0195 ns |      0.0057 |           - |           - |                24 B |
|  Combined | LegacyJitX64 | LegacyJit |     Clr | 15.067 ns | 0.0568 ns | 0.0532 ns |      0.0133 |           - |           - |                56 B |
|   Complex | LegacyJitX64 | LegacyJit |     Clr | 26.822 ns | 0.1198 ns | 0.1121 ns |      0.0229 |           - |           - |                96 B |
| Singleton |    RyuJitX64 |    RyuJit |    Core |  7.744 ns | 0.0743 ns | 0.0695 ns |           - |           - |           - |                   - |
| Transient |    RyuJitX64 |    RyuJit |    Core | 10.031 ns | 0.0172 ns | 0.0161 ns |      0.0057 |           - |           - |                24 B |
|  Combined |    RyuJitX64 |    RyuJit |    Core | 16.454 ns | 0.0564 ns | 0.0500 ns |      0.0133 |           - |           - |                56 B |
|   Complex |    RyuJitX64 |    RyuJit |    Core | 23.667 ns | 0.0410 ns | 0.0342 ns |      0.0229 |           - |           - |                96 B |

Nuget

Library Version
Singularity NuGet Badge
Singularity.Duality.core NuGet Badge
Singularity.Microsoft.DependencyInjection NuGet Badge

Random info

GitHub repo size GitHub code size in bytes

Build History

Donations

Support me by buying a beer Beerpay

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.