IoC.Container
1.1.0-beta181
See the version list below for details.
dotnet add package IoC.Container --version 1.1.0-beta181
NuGet\Install-Package IoC.Container -Version 1.1.0-beta181
<PackageReference Include="IoC.Container" Version="1.1.0-beta181" />
paket add IoC.Container --version 1.1.0-beta181
#r "nuget: IoC.Container, 1.1.0-beta181"
// Install IoC.Container as a Cake Addin
#addin nuget:?package=IoC.Container&version=1.1.0-beta181&prerelease
// Install IoC.Container as a Cake Tool
#tool nuget:?package=IoC.Container&version=1.1.0-beta181&prerelease
Simple, powerful and fast IoC container
Key features:
- One of the fastest, almost as fast as operators
new
- Produces minimal memory trafic
- Powerful auto-wiring
- Checks the auto-wiring configuration at the compile time
- Allows to not change a code design to use IoC
- Clear generic types' mapping
- The simple text metadata is supported
- Fully extensible and supports custom containers/lifetimes
- Reconfigurable on-the-fly
- Supports concurrent and asynchronous resolving
- Does not need additional dependencies
Supported platforms:
- .NET 4.0+
- .NET Core 1.0+
- .NET Standard 1.0+
Schrödinger's cat shows how it works
The reality is that
Let's create an abstraction
interface IBox<out T> { T Content { get; } }
interface ICat { bool IsAlive { get; } }
Here is our implementation
class CardboardBox<T> : IBox<T>
{
public CardboardBox(T content) => Content = content;
public T Content { get; }
public override string ToString() => Content.ToString();
}
class ShroedingersCat : ICat
{
public bool IsAlive => new Random().Next(2) == 1;
public override string ToString() => $"Is alive: {IsAlive}";
}
It is important to note that our abstraction and our implementation do not know anything about IoC containers
Add a package reference
Package Manager
Install-Package IoC.Container
.NET CLI
dotnet add package IoC.Container
Let's glue our abstraction and our implementation
class Glue : IConfiguration
{
public IEnumerable<IDisposable> Apply(IContainer container)
{
yield return container.Bind<IBox<TT>>().To<CardboardBox<TT>>();
yield return container.Bind<ICat>().To<ShroedingersCat>();
}
}
Just configure the container and check it works as expected
using (var container = Container.Create().Using<Glue>())
{
var box = container.Resolve<IBox<ICat>>();
Console.WriteLine(box);
// Func
var func = container.Resolve<Func<IBox<ICat>>>();
Console.WriteLine(func());
// Async
box = await container.Resolve<Task<IBox<ICat>>>();
Console.WriteLine(box);
// Async value
box = await container.Resolve<ValueTask<IBox<ICat>>>();
Console.WriteLine(box);
// Tuple<,>
var tuple = container.Resolve<Tuple<IBox<ICat>, ICat>>();
Console.WriteLine(tuple.Item1 + ", " + tuple.Item2);
// ValueTuple(,,)
var valueTuple = container.Resolve<(IBox<ICat> box, ICat cat, IBox<ICat> anotherBox)>();
Console.WriteLine(valueTuple.box + ", " + valueTuple.cat + ", " + valueTuple.anotherBox);
// Lazy
var lazy = container.Resolve<Lazy<IBox<ICat>>>();
Console.WriteLine(lazy.Value);
// Enumerable
var enumerable = container.Resolve<IEnumerable<IBox<ICat>>>();
Console.WriteLine(enumerable.Single());
// List
var list = container.Resolve<IList<IBox<ICat>>>();
Console.WriteLine(list[0]);
}
Under the hood
Actually these resolvers are represented just as set of operators new
that allow to create (or get) required instances.
var box = new CardboardBox<ShroedingersCat>(new ShroedingersCat());
There is only one difference - these resolvers are wrapped to compiled lambda functions and the each call of these lambdas spends some minimal time in the operator call
, but in actual scenarios it is not required to make these lambdas each time to create an instance.
When some dependencies are injected to an instance they are injected without any lambdas at all but just as a minimal set of instruction to create these dependencies:
new ShroedingersCat()
Thus this IoC container makes the minimal impact in terms of perfomrance and of memory trafic on a creation of instances of classes and might be used everywhere and everytime in accordance with the SOLID principles.
Class References
Why this one?
The results of the comparison tests for some popular IoC containers like Castle Windsor, Autofac, Unity, Ninject ...
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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. |
.NET Core | netcoreapp1.0 is compatible. netcoreapp1.1 is compatible. netcoreapp2.0 is compatible. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.0 is compatible. netstandard1.1 is compatible. netstandard1.2 is compatible. netstandard1.3 is compatible. netstandard1.4 is compatible. netstandard1.5 is compatible. netstandard1.6 is compatible. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net40 is compatible. net403 was computed. net45 is compatible. net451 was computed. net452 was computed. net46 is compatible. net461 was computed. net462 was computed. net463 was computed. net47 is compatible. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Windows Phone | wp8 was computed. wp81 was computed. wpa81 was computed. |
Windows Store | netcore was computed. netcore45 was computed. netcore451 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 1.0
- Microsoft.NETCore.App (>= 1.0.5)
-
.NETCoreApp 1.1
- Microsoft.NETCore.App (>= 1.1.2)
-
.NETCoreApp 2.0
- No dependencies.
-
.NETFramework 4.0
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
.NETFramework 4.6
- No dependencies.
-
.NETFramework 4.7
- No dependencies.
-
.NETStandard 1.0
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.1
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.2
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.4
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.5
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.6
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 2.0
- No dependencies.
NuGet packages (4)
Showing the top 4 NuGet packages that depend on IoC.Container:
Package | Downloads |
---|---|
TeamCity.VSTest.TestAdapter
Provides an integration with TeamCity for test frameworks. Usage: - Create a test project, for example using the command line: dotnet new xunit - Add the NuGet reference to this package |
|
IoC.AspNetCore
AspNetCore feature for expressions based Inversion of Control container for .NET. |
|
IoC.Interception
Interception feature for expressions based Inversion of Control container for .NET. |
|
BlingCode.Core
Package Description |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on IoC.Container:
Repository | Stars |
---|---|
Reloaded-Project/Reloaded-II
Next Generation Universal .NET Core Powered Mod Loader compatible with anything X86, X64.
|
|
DevTeam/Pure.DI
Pure DI for .NET without frameworks!
|
Version | Downloads | Last updated |
---|---|---|
1.3.8 | 204,332 | 1/14/2023 |
1.3.7 | 3,773,469 | 12/2/2021 |
1.3.6 | 1,582,270 | 7/12/2021 |
1.3.4 | 771,543 | 2/16/2021 |
1.3.3 | 855,516 | 11/11/2020 |
1.3.2 | 558,516 | 7/10/2020 |
1.3.0 | 734,548 | 4/29/2020 |
1.2.2 | 433,131 | 2/6/2020 |
1.2.0 | 150,127 | 12/22/2019 |
1.1.15 | 445,262 | 9/24/2019 |
1.1.14 | 2,048,104 | 3/21/2019 |
1.1.12 | 178,848 | 2/5/2019 |
1.1.11 | 246,537 | 10/27/2018 |