ToolBX.AutoInject
2.1.0-beta1
See the version list below for details.
dotnet add package ToolBX.AutoInject --version 2.1.0-beta1
NuGet\Install-Package ToolBX.AutoInject -Version 2.1.0-beta1
<PackageReference Include="ToolBX.AutoInject" Version="2.1.0-beta1" />
<PackageVersion Include="ToolBX.AutoInject" Version="2.1.0-beta1" />
<PackageReference Include="ToolBX.AutoInject" />
paket add ToolBX.AutoInject --version 2.1.0-beta1
#r "nuget: ToolBX.AutoInject, 2.1.0-beta1"
#:package ToolBX.AutoInject@2.1.0-beta1
#addin nuget:?package=ToolBX.AutoInject&version=2.1.0-beta1&prerelease
#tool nuget:?package=ToolBX.AutoInject&version=2.1.0-beta1&prerelease
AutoInject
A lightweight .NET library designed to make it easier for you to inject services without having to add a new line to a configuration class every time you create an injectable service.
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<ISomeService, SomeService>();
services.AddScoped<ISomeOtherService, SomeOtherService>();
services.AddSingleton<IAnotherService, AnotherService>();
services.AddSingleton<IYetAnotherService, YetAnotherService>();
//TODO Remember to add new services here manually like some sort of animal
}
What year is this? 2008? What if you have dozens or hundreds of services to inject? With [AutoInject] you can instead do it like this.
public void ConfigureServices(IServiceCollection services)
{
services.AddAutoInjectServices();
}
public interface ISomeService { }
[AutoInject(Lifetime = ServiceLifetime.Transient)]
public class SomeService : ISomeService { }
public interface ISomeOtherService { }
[AutoInject(Lifetime = ServiceLifetime.Scoped)]
public class SomeOtherService : ISomeOtherService { }
public interface IAnotherService { }
//It uses Singleton by default so no need to specify it
[AutoInject]
public class AnotherService : IAnotherService { }
public interface IYetAnotherService { }
//But knock yourself out if that's what you're into
[AutoInject(Lifetime = ServiceLifetime.Singleton)]
public class YetAnotherService : IYetAnotherService { }
Getting started
That’s all well and good but attributes are merely dust in the wind until you use them. You could place [AutoInject] on every class in your project and it wouldn’t do squat until you call the following line from your startup class (or wherever you feed your service collection before it is used by the ServiceProvider.)
public void ConfigureServices(IServiceCollection services)
{
services.AddAutoInjectServices();
}
And that’s it! Now your [AutoInject] tags work everywhere- even in other loaded assemblies that use them.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. 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. |
-
net7.0
- Microsoft.Extensions.Configuration.Binder (>= 7.0.4)
- Microsoft.Extensions.Configuration.Json (>= 7.0.0)
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
- Microsoft.Extensions.Options (>= 7.0.1)
- ToolBX.Reflection4Humans.TypeFetcher (>= 2.1.0-beta1)
NuGet packages (13)
Showing the top 5 NuGet packages that depend on ToolBX.AutoInject:
Package | Downloads |
---|---|
ToolBX.Eloquentest
A simple to use .NET unit testing framework built on top of MSTest and Moq. It also includes built-in support for services that are injected using [AutoInject]. |
|
ToolBX.Mathemancy
A bundle for generic geometry types such as Vector2<T>, Size<T> and Rectangle<T> |
|
ToolBX.NetAbstractions
Abstractions for .NET base types such as File and Directory to provide easier means to mock low-level operations. |
|
ToolBX.Mathemancy.Randomness
Services that generate random numbers and such. |
|
ToolBX.AssemblyInitializer
Helps decouple initialization logic by splitting it into AssemblyInitializer classes. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
3.0.1 | 1,907 | 9/30/2024 |
3.0.1-beta1 | 103 | 9/28/2024 |
3.0.0 | 6,248 | 9/26/2024 |
3.0.0-beta2 | 322 | 9/23/2024 |
3.0.0-beta1 | 120 | 9/23/2024 |
2.2.0 | 10,598 | 1/11/2024 |
2.2.0-beta7 | 582 | 1/7/2024 |
2.2.0-beta6 | 334 | 12/14/2023 |
2.2.0-beta5 | 325 | 12/12/2023 |
2.2.0-beta4 | 324 | 11/16/2023 |
2.2.0-beta3 | 304 | 10/21/2023 |
2.2.0-beta2 | 398 | 7/26/2023 |
2.2.0-beta1 | 420 | 7/26/2023 |
2.1.1 | 6,933 | 10/24/2023 |
2.1.1-beta1 | 274 | 10/21/2023 |
2.1.0 | 6,184 | 7/28/2023 |
2.1.0-beta1 | 408 | 6/28/2023 |
2.0.2 | 3,406 | 6/19/2023 |
2.0.1 | 2,138 | 4/23/2023 |
2.0.0 | 1,242 | 11/9/2022 |
2.0.0-beta1 | 782 | 9/20/2022 |
1.0.2 | 4,432 | 6/15/2022 |
1.0.1.1-beta | 2,386 | 5/12/2022 |
1.0.1 | 2,054 | 1/23/2022 |
1.0.0 | 944 | 11/10/2021 |