IoC.AspNetCore
1.1.0-beta217
See the version list below for details.
dotnet add package IoC.AspNetCore --version 1.1.0-beta217
NuGet\Install-Package IoC.AspNetCore -Version 1.1.0-beta217
<PackageReference Include="IoC.AspNetCore" Version="1.1.0-beta217" />
paket add IoC.AspNetCore --version 1.1.0-beta217
#r "nuget: IoC.AspNetCore, 1.1.0-beta217"
// Install IoC.AspNetCore as a Cake Addin
#addin nuget:?package=IoC.AspNetCore&version=1.1.0-beta217&prerelease
// Install IoC.AspNetCore as a Cake Tool
#tool nuget:?package=IoC.AspNetCore&version=1.1.0-beta217&prerelease
Simple, powerful and fast IoC container
IoC.Container provides the following benefits:
- 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
- Flexible autowiring configuration (as example a custom Aspect Oriented Autowiring)
- Fully extensible and supports custom containers/lifetimes
- Reconfigurable on-the-fly
- Supports concurrent and asynchronous resolving
- Does not need additional dependencies
- Supports ASP.NET Core
- Supports Windows Presentation Foundation
- Supports Universal Windows Platform
- Supports Windows Communication Foundation
NuGet packages:
- IoC.Container
- IoC.Container.Source (embedding in code)
- IoC.AspNetCore
- IoC.AspNetCore.Source (embedding in code)
Supported platforms:
- .NET 4.0+
- .NET Core 1.0+
- .NET Standard 1.0+
- UWP 10+
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 the package reference
IoC.Container ships entirely as NuGet packages. Using NuGet packages allows you to optimize your application to include only the necessary dependencies.
Package Manager
Install-Package IoC.Container
.NET CLI
dotnet add package IoC.Container
Let's glue all together
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 a set of operators new
which allow to create (or to get) required instances.
var box = new CardboardBox<ShroedingersCat>(new ShroedingersCat());
There is only one difference - these resolvers are wrapped to compiled lambda-functions and an each call of these lambda-functions spends some minimal time in the operator call
, but in actual scenarios it is not required to make these calls each time to create instances.
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.
ASP.NET Core
Add the package reference
Package Manager
Install-Package IoC.AspNetCore
.NET CLI
dotnet add package IoC.AspNetCore
Change IoC container and configure it at Startup
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddControllersAsServices();
// Create container
var container = Container.Create().Using(new AspNetCoreFeature(services));
// Configure container
container.Using<Glue>();
// Resolve IServiceProvider
return container.Resolve<IServiceProvider>();
}
For more information see this sample.
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 | 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
- IoC.Container (>= 1.1.0-beta217)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 1.1.1)
- Microsoft.NETCore.App (>= 1.0.5)
-
.NETCoreApp 1.1
- IoC.Container (>= 1.1.0-beta217)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 1.1.1)
- Microsoft.NETCore.App (>= 1.1.2)
-
.NETCoreApp 2.0
- IoC.Container (>= 1.1.0-beta217)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.0.0)
-
.NETFramework 4.5
- IoC.Container (>= 1.1.0-beta217)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 1.1.1)
-
.NETFramework 4.6
- IoC.Container (>= 1.1.0-beta217)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 1.1.1)
-
.NETFramework 4.7
- IoC.Container (>= 1.1.0-beta217)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 1.1.1)
-
.NETStandard 1.0
- IoC.Container (>= 1.1.0-beta217)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 1.1.1)
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.1
- IoC.Container (>= 1.1.0-beta217)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 1.1.1)
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.2
- IoC.Container (>= 1.1.0-beta217)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 1.1.1)
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.3
- IoC.Container (>= 1.1.0-beta217)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 1.1.1)
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.4
- IoC.Container (>= 1.1.0-beta217)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 1.1.1)
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.5
- IoC.Container (>= 1.1.0-beta217)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 1.1.1)
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.6
- IoC.Container (>= 1.1.0-beta217)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 1.1.1)
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 2.0
- IoC.Container (>= 1.1.0-beta217)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 1.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.3.8 | 332 | 1/14/2023 |
1.3.7 | 299 | 12/2/2021 |
1.3.6 | 429 | 7/12/2021 |
1.3.5-beta449 | 196 | 4/6/2021 |
1.3.4 | 334 | 2/16/2021 |
1.3.3 | 530 | 11/11/2020 |
1.3.2 | 472 | 7/10/2020 |
1.3.0 | 509 | 4/29/2020 |
1.2.2 | 503 | 2/6/2020 |
1.2.0 | 559 | 12/22/2019 |
1.1.15 | 557 | 9/24/2019 |
1.1.14 | 594 | 3/21/2019 |
1.1.13 | 593 | 3/8/2019 |
1.1.12 | 669 | 2/5/2019 |
1.1.11 | 725 | 10/27/2018 |
1.1.10 | 741 | 10/8/2018 |
1.1.9 | 708 | 10/7/2018 |
1.1.8 | 711 | 9/26/2018 |
1.1.7 | 816 | 8/16/2018 |
1.1.6 | 809 | 7/19/2018 |