Faster.Ioc
1.0.0.3
See the version list below for details.
dotnet add package Faster.Ioc --version 1.0.0.3
NuGet\Install-Package Faster.Ioc -Version 1.0.0.3
<PackageReference Include="Faster.Ioc" Version="1.0.0.3" />
paket add Faster.Ioc --version 1.0.0.3
#r "nuget: Faster.Ioc, 1.0.0.3"
// Install Faster.Ioc as a Cake Addin #addin nuget:?package=Faster.Ioc&version=1.0.0.3 // Install Faster.Ioc as a Cake Tool #tool nuget:?package=Faster.Ioc&version=1.0.0.3
Faster.Ioc - fastest ioc container
Faster.Ioc is an IoC container for Microsoft .NET. It manages dependencies between classes so that applications stay easy to change as they grow in size and complexity.
About
Faster.Ioc is an incredibly fast Ioc container with endless possibilities. Faster.ioc supports the following:
- Scoped lifetimes (Singleton, Transient, Scoped)
- Multi registrations, no more pesky factories...
- Conditional overrides
- Ienumerable<T>
- Asp.net core features
- Open and closed generics
- Child containers
- Store registrations by key
- Retrieve all registrations of the same interface
- Will always resolve constructor with largest parameters
How to use
- Install nuget package Faster.Ioc to your project
dotnet add package Faster.Ioc
- Create a Container
var container = new Container();
//add registrations with different lifetimes
container.Register<IAnimal, Cow>(Lifetime.Singleton);
container.Register<IAnimal, Horse>(Lifetime.Transient);
container.Register<IAnimal, Bull>(Lifetime.Scoped);
// register by key
container.Register<IAnimal, Goose>(Lifetime.Scoped, "Goose")
// will always resolve the first registration of IAnimal, which in this case is a Cow
var cow = container.Resolve<IAnimal>();
// Resolve by key
var goose = container.Resolve("Goose");
//Cow, Horse and Bull
var animals = container.ResolveAll<IAnimal
Advanced
- Conditional - overriding a parameter with a different implementation
var container = new Container();
container.Register<IAnimal, Cow>(Lifetime.Singleton);
container.Register<IAnimal, Horse>(Lifetime.Transient);
//Create override of Farm which be default, since it has an IAnimal parameter would resolve a Cow, but now it will resolve a Horse
//Types used in an override need to be registered!
container.RegisterOverride<IFarm, Farm>(() => new Farm(New Horse()));
// will always resolve the first registration of IAnimal, which in this case is a Cow
var cow = container.Resolve<IFarm>();
public class Farm
{
public Animal{get; set;}
public Farm(IAnimal animal)
{
Animal = animal;
}
}
- Ienumerable<T>
var container = new Container();
container.Register<IAnimal, Cow>(Lifetime.Singleton);
container.Register<IAnimal, Horse>(Lifetime.Singleton);
//Create override of Farm which be default, since it has an IAnimal parameter would resolve a Cow, but now it will resolve a Horse
//Types used in an override need to be registered!
container.Register<IFarm, Farm>();
public class Farm
{
public IEnumerable<IAnimal> {get; private set;}
public Farm(IEnumerable<IAnimal> animals)
{
Animals = animals;
}
}
- OpenGenerics<T>
var container = new Container();
container.Register<>(typeof(IGeneric<>, Generic<>)Lifetime.Singleton);
container.Register<IFarm, Farm>();
public class Farm
{
public Generic<IAnimal> { get; private set;}
public Farm(IGeneric<IAnimal> animals)
{
Animals = animals;
}
}
- Closed Generics<fixed>
var container = new Container();
container.Register<>(typeof(IGeneric<int>, Generic<int>)Lifetime.Singleton);
container.Register<IFarm, Farm>();
public class Farm
{
public Generic<int> { get; private set;}
public Farm(IGeneric<int> animals)
{
Animals = animals;
}
}
- Scoped Lifetime
Container container = new Container();
container.Register<IDisposeableOne>(() => new DisposeableOne(), Lifetime.Scoped);
using (var factory = container.CreateScope())
{
//Act
var instance = factory.ServiceProvider.GetService(typeof(IDisposeableOne));
var instance2 = factory.ServiceProvider.GetService(typeof(IDisposeableOne));
//Assert
Assert.IsTrue(instance == instance2);
}
Disposable
The lifetime of objects implementing IDisposable interface is something to keep in mind. The Container will keep track of all objects implementing IDisposable (Singletons and transient). By default Faster.Map will dispose all objects at shutdown or when .Dispose() is called. This is also when the memory is released by the garbage collector, all references stored in the Container will be gone. If this is troublesome you can either use a Scoped lifetimes or a ChildContainer
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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 Framework | net472 is compatible. net48 is compatible. net481 was computed. |
-
.NETFramework 4.7.2
- Faster.Map (>= 3.0.3.8)
- FastExpressionCompiler (>= 3.3.3)
- FastExpressionCompiler.LightExpression (>= 3.3.3)
- Microsoft.Extensions.DependencyInjection (>= 5.0.2)
-
.NETFramework 4.8
- Faster.Map (>= 3.0.3.8)
- FastExpressionCompiler (>= 3.3.3)
- FastExpressionCompiler.LightExpression (>= 3.3.3)
- Microsoft.Extensions.DependencyInjection (>= 5.0.2)
-
net5.0
- Faster.Map (>= 3.0.3.8)
- FastExpressionCompiler (>= 3.3.3)
- FastExpressionCompiler.LightExpression (>= 3.3.3)
- Microsoft.Extensions.DependencyInjection (>= 5.0.2)
-
net6.0
- Faster.Map (>= 3.0.3.8)
- FastExpressionCompiler (>= 3.3.3)
- FastExpressionCompiler.LightExpression (>= 3.3.3)
- Microsoft.Extensions.DependencyInjection (>= 5.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
minor performance changes