Aoxe.DependencyInjection.Extensions 2025.2.2

dotnet add package Aoxe.DependencyInjection.Extensions --version 2025.2.2                
NuGet\Install-Package Aoxe.DependencyInjection.Extensions -Version 2025.2.2                
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="Aoxe.DependencyInjection.Extensions" Version="2025.2.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Aoxe.DependencyInjection.Extensions --version 2025.2.2                
#r "nuget: Aoxe.DependencyInjection.Extensions, 2025.2.2"                
#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.
// Install Aoxe.DependencyInjection.Extensions as a Cake Addin
#addin nuget:?package=Aoxe.DependencyInjection.Extensions&version=2025.2.2

// Install Aoxe.DependencyInjection.Extensions as a Cake Tool
#tool nuget:?package=Aoxe.DependencyInjection.Extensions&version=2025.2.2                

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.

JetBrains

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
2025.2.2 197 11/15/2024
2025.2.0 80 11/15/2024
2025.1.0 86 11/15/2024
2024.1.2 214 11/4/2024
2024.1.0 89 11/4/2024