NanoIoC 2.0.5
See the version list below for details.
dotnet add package NanoIoC --version 2.0.5
NuGet\Install-Package NanoIoC -Version 2.0.5
<PackageReference Include="NanoIoC" Version="2.0.5" />
paket add NanoIoC --version 2.0.5
#r "nuget: NanoIoC, 2.0.5"
// 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
NanoIoC
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 TypeProcessor
s 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 Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net46 is compatible. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
This package has no dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on NanoIoC:
Package | Downloads |
---|---|
MustardBlack.Hosting.AspNet
MustardBlack.Hosting.AspNet library. |
|
MustardBlack.ViewEngines.Razor
MustardBlack.ViewEngines.Razor library. |
|
MustardBlack.Hosting.AspNetCore
MustardBlack.Hosting.AspNetCore library. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.5.43 | 12,488 | 7/26/2019 |
2.5.38 | 2,045 | 4/17/2019 |
2.5.37 | 649 | 4/16/2019 |
2.5.36 | 660 | 4/16/2019 |
2.5.35 | 676 | 4/16/2019 |
2.4.34 | 685 | 4/16/2019 |
2.4.33 | 678 | 4/9/2019 |
2.4.32 | 670 | 4/9/2019 |
2.4.31 | 693 | 2/21/2019 |
2.3.30-prerelease | 546 | 2/21/2019 |
2.3.29-prerelease | 591 | 2/20/2019 |
2.3.28-prerelease | 914 | 2/18/2019 |
2.3.26-prerelease | 577 | 2/15/2019 |
2.2.24 | 754 | 2/11/2019 |
2.2.23 | 827 | 1/30/2019 |
2.2.20 | 735 | 1/30/2019 |
2.2.19 | 783 | 1/22/2019 |
2.1.9 | 820 | 11/14/2018 |
2.1.7 | 955 | 10/1/2018 |
2.1.6 | 983 | 8/10/2018 |
2.1.0 | 1,165 | 7/11/2018 |
2.0.5 | 1,271 | 6/27/2018 |
2.0.4 | 62,606 | 7/30/2018 |