UIoC 1.0.8
dotnet add package UIoC --version 1.0.8
NuGet\Install-Package UIoC -Version 1.0.8
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="UIoC" Version="1.0.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="UIoC" Version="1.0.8" />
<PackageReference Include="UIoC" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add UIoC --version 1.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: UIoC, 1.0.8"
#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.
#addin nuget:?package=UIoC&version=1.0.8
#tool nuget:?package=UIoC&version=1.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
UIoC Container
The UIoC is a lightweight dependency injection container with basic functionality for the .NET Framework.
Installation
Install UIoC with the command Install-Package UIoC
or get it from the NuGet.org.
Quick Start Guide
Create Container
var container = new Container();
Types Registration
Add type with interface
// Add type
container.AddType<IMyType, MyType>();
// Get an instance of the registered type
var myType = container.Get<IMyType>();
Add type with resolve name
// Add type
container.AddType<IMyType, MyTypeA>("keyA");
container.AddType<IMyType, MyTypeB>("keyB");
// Get instances of registered types by name
var myTypeA = container.Get<IMyType>("keyA");
var myTypeB = container.Get<IMyType>("keyB");
Add type without interface
// Add type
container.AddType<MyType>();
// Get an instance of the registered type
var myType = container.Get<MyType>();
Singleton, Instance, and Factory Registration
Add singleton
// Add singleton
container.AddSingleton<IMyType, MyType>();
// Get the instance of the singleton
var myType = container.Get<IMyType>();
Add instance
// Add instance
container.AddInstance<IMyType>(new MyType("My Instance Type"));
// Get the instance
var myType = container.Get<IMyType>();
Add factory
// Add factory
container.AddFactory<IMyType>(() => new MyType("My Factory Produced Type"));
// Get an instance
var myType = container.Get<IMyType>();
Inject into the constructor
Inject type
class MyType { ... }
class MyOuterTypeA {
public MyOuterTypeA(MyType myType) { ... }
}
// Add types
container.AddType<MyType>();
container.AddType<MyOuterTypeA>();
// Get an instance of the MyTypeOuterA with MyType
var myOuterTypeA = container.Get<MyOuterTypeA>();
Inject type with resolve name
interface IMyType { ... }
class MyTypeA : IMyType { ... }
class MyTypeB : IMyType { ... }
class MyOuterTypeB {
public MyOuterTypeB([Inject("keyB")]IMyType myType) { ... }
}
// Add types
container.AddType<IMyType, MyTypeA>("keyA");
container.AddType<IMyType, MyTypeB>("keyB");
container.AddType<MyOuterTypeB>();
// Get an instance of the MyTypeOuter with MyTypeB
var myOuterTypeB = container.Get<MyOuterTypeB>();
Inject assembly types
Inject all types of assembly
// Inject all types from the current assembly
container.AddAllFromAssembly(Assembly.GetExecutingAssembly());
Specify resolve type and name for injection from assembly
interface IMyType { ... }
// Specify resolve type
[Type(typeof(IMyType))]
class MyTypeC : IMyType { ... }
// Specify resolve type and resolve name
[Singleton(typeof(IMyType), "MySingleton")]
class MyTypeD : IMyType { ... }
// Load only types with attributes
container.AddByAttributeFromAssembly(Assembly.GetExecutingAssembly());
Create type without registration
class MyType { ... }
class MyUnregstredType {
public MyUnregstredType(MyType myType) { ... }
}
// Add type
container.AddType<IMyType, MyType>();
// Create type without registration with injection into the constructor
var myUnregstredType = container.Create<MyUnregstredType>();
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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. 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 | tizen40 was computed. tizen60 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.
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on UIoC:
Package | Downloads |
---|---|
Deropt.Core
Deropt for the .NET |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
1.0.8 | 340 | 10/21/2023 | |
1.0.7 | 153 | 9/16/2023 | |
1.0.6 | 168 | 9/10/2023 | |
1.0.5 | 181 | 7/16/2023 | |
1.0.4 | 192 | 7/16/2023 | |
1.0.3 | 176 | 7/15/2023 | |
1.0.2 | 166 | 7/15/2023 | |
1.0.1 | 184 | 7/14/2023 | |
1.0.0.16 | 198 | 7/11/2023 | |
1.0.0.15 | 183 | 7/10/2023 | |
1.0.0.14 | 179 | 7/8/2023 | |
1.0.0.13 | 525 | 1/12/2022 | |
1.0.0.12 | 507 | 1/12/2022 | |
1.0.0.11 | 336 | 1/8/2022 | |
1.0.0.10 | 346 | 1/8/2022 | |
1.0.0.9 | 393 | 8/27/2021 | |
1.0.0.8 | 353 | 8/25/2021 | |
1.0.0.7 | 377 | 8/21/2021 | |
1.0.0.6 | 394 | 8/21/2021 | |
1.0.0.4 | 351 | 7/2/2021 | |
1.0.0.3 | 396 | 6/30/2021 | |
1.0.0.2 | 412 | 6/29/2021 |