IoC.AspNetCore 1.1.0-beta222

This is a prerelease version of IoC.AspNetCore.
There is a newer version of this package available.
See the version list below for details.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package IoC.AspNetCore --version 1.1.0-beta222
NuGet\Install-Package IoC.AspNetCore -Version 1.1.0-beta222
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IoC.AspNetCore" Version="1.1.0-beta222" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IoC.AspNetCore --version 1.1.0-beta222
#r "nuget: IoC.AspNetCore, 1.1.0-beta222"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install IoC.AspNetCore as a Cake Addin
#addin nuget:?package=IoC.AspNetCore&version=1.1.0-beta222&prerelease

// Install IoC.AspNetCore as a Cake Tool
#tool nuget:?package=IoC.AspNetCore&version=1.1.0-beta222&prerelease

Simple, powerful and fast IoC container

License

IoC.Container provides the following benefits:

NuGet packages:

  • IoC.Container
    • NuGet
  • IoC.Container.Source (embedding in code)
    • NuGet
  • IoC.AspNetCore
    • NuGet
  • IoC.AspNetCore.Source (embedding in code)
    • NuGet

Supported platforms:

Schrödinger's cat shows how it works

The reality is that

Cat

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 ...

Cat

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 334 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 510 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