NanoIoC 2.0.5

.NET Framework 4.6
There is a newer version of this package available.
See the version list below for details.
dotnet add package NanoIoC --version 2.0.5
NuGet\Install-Package NanoIoC -Version 2.0.5
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="NanoIoC" Version="2.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NanoIoC --version 2.0.5
#r "nuget: NanoIoC, 2.0.5"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install NanoIoC as a Cake Addin
#addin nuget:?package=NanoIoC&version=2.0.5

// Install NanoIoC as a Cake Tool
#tool nuget:?package=NanoIoC&version=2.0.5


A tiny IoC container, does exactly what you want, and only that.

Getting Started

Container.Global is a static instance of IContainer. You can use this as your entry point.

Manually Registering Dependencies

Use either of these methods:

<pre> void IContainer.Register<TAbstract, TConcrete>(Lifecycle lifecycle = Lifecycle.Singleton); void IContainer.Register(Type abstract, Type concrete, Lifecycle lifecycle = Lifecycle.Singleton); </pre>

You will typically want to put your registrations inside an IContainerRegistry.

NanoIoC will find all IContainerRegistrys in all assemblies in the application's base directory (excluding those that start with the System namespace)

To run all the registries, use:

<pre> void IContainer.RunAllRegistries(); </pre>

Auto Registering Dependencies

You can create TypeProcessors that scan all types allowing you to auto-wire them up.

NanoIoC will find all TypeProcesors in all assemblies in the application's base directory (excluding those that start with the System namespace)

For example:

<pre> void IContainer.RunAllTypeProcessors(); </pre>

Where one of your TypeProcessors might look like: <pre> public class ExampleTypeProcessor : ITypeProcessor { public void Process(Type type, IContainer container) { if(typeof(MyInterface).IsAssignableFrom(type) && type != typeof(MyInterface)) container.Register(typeof(MyInterface), type, Lifecycle.Singleton); } } </pre>

Resolving Dependencies:

Use either of these methods:

<pre> T IContainer.Resolve<T>(); object IContainer.Resolve(Type type); </pre>

You can resolve concrete types that aren't registered, as long as all their dependencies are registered or directly constructable.

You can get all registered types: <pre> IEnumerable<T> IContainer.ResolveAll<T>() IEnumerable IContainer.ResolveAll(Type type); </pre>

Injecting instances:

You can inject existing instances:

<pre> void IContainer.Inject<T>(T instance, Lifecycle lifeCycle = Lifecycle.Singleton); void IContainer.Inject(object instance, Type type, Lifecycle lifecycle); </pre>

Product Versions
.NET Framework net46 net461 net462 net463 net47 net471 net472 net48
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on NanoIoC:

Package Downloads

MustardBlack.ViewEngines.Razor library.


MustardBlack.Hosting.AspNet library.


MustardBlack.Hosting.AspNetCore library.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.5.43 10,135 7/26/2019
2.5.38 1,781 4/17/2019
2.5.37 498 4/16/2019
2.5.36 514 4/16/2019
2.5.35 523 4/16/2019
2.4.34 524 4/16/2019
2.4.33 519 4/9/2019
2.4.32 495 4/9/2019
2.4.31 529 2/21/2019
2.3.30-prerelease 446 2/21/2019
2.3.29-prerelease 509 2/20/2019
2.3.28-prerelease 838 2/18/2019
2.3.26-prerelease 494 2/15/2019
2.2.24 596 2/11/2019
2.2.23 651 1/30/2019
2.2.20 584 1/30/2019
2.2.19 604 1/22/2019
2.1.9 646 11/14/2018
2.1.7 766 10/1/2018
2.1.6 794 8/10/2018
2.1.0 978 7/11/2018
2.0.5 1,071 6/27/2018
2.0.4 42,295 7/30/2018