https://github.com/aoxetech/aoxe.dependencyinjection.extensions
The extensions for DependencyInjection
https://github.com/aoxetech/aoxe.dependencyinjection.extensions
Last synced: 5 months ago
JSON representation
The extensions for DependencyInjection
- Host: GitHub
- URL: https://github.com/aoxetech/aoxe.dependencyinjection.extensions
- Owner: AoxeTech
- License: mit
- Created: 2024-11-01T08:28:45.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-07-12T01:37:29.000Z (11 months ago)
- Last Synced: 2025-07-22T08:56:08.240Z (11 months ago)
- Language: C#
- Size: 39.1 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Aoxe.DependencyInjection.Extensions
Aoxe.DependencyInjection.Extensions provides extension methods for Microsoft's Dependency Injection container to simplify service registration with Lazy\ 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\
- AddSingletonWithLazy
- AddScopedWithLazy
- AddTransientWithLazy
- Support for both type and factory-based registrations
- Simplifies the use of Lazy\ in dependency injection scenarios
## Installation
To install the package, add the following to your project file:
```xml
```
Or use the .NET CLI:
```bash
dotnet add package Aoxe.DependencyInjection.Extensions
```
## Usage
First, include the namespace:
```csharp
using Aoxe.DependencyInjection.Extensions;
```
### Registering Services
#### Singleton Services
Use the 'AddSingletonWithLazy' method to register singleton services with Lazy\ support:
```csharp
services.AddSingletonWithLazy();
```
#### Scoped Services
For scoped services, use the 'AddScopedWithLazy' method:
```csharp
services.AddScopedWithLazy();
```
#### Transient Services
For transient services, use the 'AddTransientWithLazy' method:
```csharp
services.AddTransientWithLazy();
```
### Accessing Services
Inject Lazy\ into your classes to defer service instantiation:
```csharp
public class MyController
{
private readonly Lazy _myService;
public MyController(Lazy 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](https://github.com/AoxeTech/Aoxe.DependencyInjection.Extensions).
---
Thank`s for [JetBrains](https://www.jetbrains.com/) for the great support in providing assistance and user-friendly environment for my open source projects.
[](https://www.jetbrains.com/community/opensource/#support)