Aoxe.DependencyInjection.Extensions
2024.1.0
See the version list below for details.
dotnet add package Aoxe.DependencyInjection.Extensions --version 2024.1.0
NuGet\Install-Package Aoxe.DependencyInjection.Extensions -Version 2024.1.0
<PackageReference Include="Aoxe.DependencyInjection.Extensions" Version="2024.1.0" />
paket add Aoxe.DependencyInjection.Extensions --version 2024.1.0
#r "nuget: Aoxe.DependencyInjection.Extensions, 2024.1.0"
// Install Aoxe.DependencyInjection.Extensions as a Cake Addin #addin nuget:?package=Aoxe.DependencyInjection.Extensions&version=2024.1.0 // Install Aoxe.DependencyInjection.Extensions as a Cake Tool #tool nuget:?package=Aoxe.DependencyInjection.Extensions&version=2024.1.0
Aoxe.DependencyInjection.Extensions
Aoxe.DependencyInjection.Extensions provides extension methods for Microsoft's Dependency Injection container to simplify service registration with Lazy<T> support. These extensions allow for deferred instantiation of services, improving performance by delaying object creation until it's actually needed.
Features
- Extension methods to register services with Lazy<T>
- AddSingletonWithLazy
- AddScopedWithLazy
- AddTransientWithLazy
- Support for both type and factory-based registrations
- Simplifies the use of Lazy<T> in dependency injection scenarios
Installation
To install the package, add the following to your project file:
<PackageReference Include="Aoxe.DependencyInjection.Extensions" Version="2024.1.0" />
Or use the .NET CLI:
dotnet add package Aoxe.DependencyInjection.Extensions
Usage
First, include the namespace:
using Aoxe.DependencyInjection.Extensions;
Registering Services
Singleton Services
Use the 'AddSingletonWithLazy' method to register singleton services with Lazy<T> support:
services.AddSingletonWithLazy<IMyService, MyServiceImplementation>();
Scoped Services
For scoped services, use the 'AddScopedWithLazy' method:
services.AddScopedWithLazy<IMyService, MyServiceImplementation>();
Transient Services
For transient services, use the 'AddTransientWithLazy' method:
services.AddTransientWithLazy<IMyService, MyServiceImplementation>();
Accessing Services
Inject Lazy<T> into your classes to defer service instantiation:
public class MyController
{
private readonly Lazy<IMyService> _myService;
public MyController(Lazy<IMyService> myService)
{
_myService = myService;
}
public void DoWork()
{
// The IMyService instance is created only when accessed
_myService.Value.PerformOperation();
}
}
Examples
Refer to the unit tests for more examples:
- AddSingletonUnitTest.cs
- AddScopedUnitTest.cs
- AddTransientUnitTest.cs
License
This project is licensed under the MIT License.
Contributing
Contributions are welcome! Please submit issues or pull requests to the GitHub repository.
Thank`s for JetBrains for the great support in providing assistance and user-friendly environment for my open source projects.
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 is compatible. 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 is compatible. |
.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. |
-
.NETStandard 2.0
-
net8.0
-
net9.0
NuGet packages (5)
Showing the top 5 NuGet packages that depend on Aoxe.DependencyInjection.Extensions:
Package | Downloads |
---|---|
Aoxe.MailKit
The aoxe email provider implement by MailKit. |
|
Aoxe.Aws.SimpleEmail
The aoxe email provider implement by Amazon.SimpleEmailV2. |
|
Aoxe.SmtpClient
The aoxe email provider implement by SmtpClient. |
|
Aoxe.Azure.Email
The aoxe email provider implement by Azure.Communication.Email. |
|
Aoxe.Mongo
The dependency injection extensions for Aoxe.Mongo.Client. |
GitHub repositories
This package is not used by any popular GitHub repositories.