IoCTools.Abstractions
0.4.0
See the version list below for details.
dotnet add package IoCTools.Abstractions --version 0.4.0
NuGet\Install-Package IoCTools.Abstractions -Version 0.4.0
<PackageReference Include="IoCTools.Abstractions" Version="0.4.0" />
<PackageVersion Include="IoCTools.Abstractions" Version="0.4.0" />
<PackageReference Include="IoCTools.Abstractions" />
paket add IoCTools.Abstractions --version 0.4.0
#r "nuget: IoCTools.Abstractions, 0.4.0"
#:package IoCTools.Abstractions@0.4.0
#addin nuget:?package=IoCTools.Abstractions&version=0.4.0
#tool nuget:?package=IoCTools.Abstractions&version=0.4.0
IoCTools
This repository provides various useful tools for simplifying and streamlining the process of working with Inversion of Control (IoC) in .NET, focusing on ASP.NET services. This project includes a source generator that eliminates much of the boilerplate associated with service registration and dependency injection in .NET.
Features
While this project is in alpha and under active development, many features are already functional.
Self-Describing Services
Services often have specific lifetimes in mind. For example, singleton services persist values during the app session.
IoCTools lets the service itself define its lifetime, removing the need for explicit registration in Program.cs.
Example:
Before (without IoCTools):
// in the service class
namespace SampleProject.Services;
public class SomeService : ISomeService
{
private readonly int _someValue = 1;
}
// in Program.cs
builder.Services.AddSingleton<ISomeService, SomeService>();
After (with IoCTools):
// in the service class
namespace SampleProject.Services;
[Service(Lifetime.Singleton)]
public partial class SomeService : ISomeService
{
private readonly int _someValue = 1;
}
// in Program.cs
builder.Services.RegisterSampleProjectServices();
The service now defines its own lifetime, and registration is streamlined with a single method.
Intuitive Dependency Injection
Dependency injection no longer needs verbose constructors or repetitive field assignments.
Example:
Before (traditional DI):
namespace SampleProject.Services;
public class SomeService(IOtherService otherService, IAnotherService anotherService,
IYetAnotherService yetAnotherService, ISomehowAnotherService somehowAnotherService)
: ISomeService
{
private readonly IOtherService _otherService = otherService;
private readonly IAnotherService _anotherService = anotherService;
private readonly IYetAnotherService _yetAnotherService = yetAnotherService;
private readonly ISomehowAnotherService _somehowAnotherService = somehowAnotherService;
private readonly int _someValue = 1;
}
After (with IoCTools):
namespace SampleProject.Services;
[Service]
public partial class SomeService : ISomeService
{
[Inject] private readonly IOtherService _otherService;
[Inject] private readonly IAnotherService _anotherService;
[Inject] private readonly IYetAnotherService _yetAnotherService;
[Inject] private readonly ISomehowAnotherService _somehowAnotherService;
private readonly int _someValue = 1;
}
IoCTools generates the constructor, simplifying DI management. It supports dependencies of any generic depth, such as
IEnumerable<T>.
Streamlined Service Registration
IoCTools eliminates repetitive service registration by generating an extension method to register all [Service]
-annotated classes automatically.
Before:
builder.Services.AddSingleton<ISomeService, SomeService>();
builder.Services.AddScoped<IAnotherService, AnotherService>();
builder.Services.AddTransient<IOtherService, OtherService>();
After:
builder.Services.RegisterSampleProjectServices();
This method is project-specific, avoiding naming conflicts when multiple projects use IoCTools.
Generic Service Support
IoCTools fully supports the registration of generic services.
Example:
namespace SampleProject.Services;
[Service]
public class GenericService<T> : IGenericService<T>
{
}
Generated Code:
services.AddScoped(typeof(IGenericService<>), typeof(GenericService<>));
Excluding Services from Registration
For cases where a service shouldn’t be registered (e.g., controllers or handlers), use [UnregisteredService] to
exclude it explicitly.
namespace SampleProject.Controllers;
[UnregisteredService]
public class MyController : ControllerBase
{
}
DependsOn: Declarative Dependency Injection
DependsOn offers a concise way to define dependencies with default naming conventions.
Example:
namespace SampleProject.Services;
[Service]
[DependsOn<IOtherService, IAnotherService, IYetAnotherService, ISomehowAnotherService>]
public partial class SomeService : ISomeService
{
private readonly int _someValue = 1;
}
IoCTools generates fields for these dependencies, allowing the service to use them directly.
You can customize field naming with the following options:
namingConvention: UseCamelCase(default),PascalCase, orSnakeCase.stripI: Removes the leadingIin interface names (default:true).prefix: Adds a prefix to field names (default:_).
Example with Customization:
[DependsOn<IOtherService, IAnotherService>(namingConvention: NamingConvention.PascalCase, prefix: "field_")]
[DependsOn<IYetAnotherService, ISomehowAnotherService>]
public partial class SomeService : ISomeService
{
}
Development Status
IoCTools is in active development, with public pre-release NuGet packages available. Expect breaking changes as the project evolves.
Feel free to contribute or report issues!
| 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.9.1 | 89 | 5/23/2026 |
| 1.8.0 | 1,233 | 5/12/2026 |
| 1.7.3 | 1,568 | 5/6/2026 |
| 1.7.2 | 88 | 5/6/2026 |
| 1.7.1 | 94 | 5/6/2026 |
| 1.6.1 | 98 | 4/29/2026 |
| 1.6.0 | 91 | 4/29/2026 |
| 1.5.1 | 143 | 4/12/2026 |
| 1.4.0 | 211 | 3/21/2026 |
| 1.3.0 | 118 | 1/24/2026 |
| 1.2.0 | 403 | 11/18/2025 |
| 1.1.0 | 294 | 11/12/2025 |
| 1.0.0 | 198 | 9/10/2025 |
| 1.0.0-alpha | 243 | 8/28/2025 |
| 0.4.1 | 177 | 11/30/2024 |
| 0.4.0 | 150 | 11/30/2024 |
| 0.3.0 | 214 | 3/18/2024 |
| 0.2.6 | 187 | 2/6/2024 |
| 0.2.5 | 309 | 2/6/2024 |
| 0.2.4 | 184 | 2/6/2024 |
Initial alpha release