Ling.AutoInject
1.0.0
Source generator compatibility issue: these versions require Roslyn 4.14 and fail with CS9057 on supported .NET 6/8 and older Visual Studio compiler hosts. Upgrade to Ling.AutoInject 1.4.1, which supports Roslyn 4.3+.
See the version list below for details.
dotnet add package Ling.AutoInject --version 1.0.0
NuGet\Install-Package Ling.AutoInject -Version 1.0.0
<PackageReference Include="Ling.AutoInject" Version="1.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Ling.AutoInject" Version="1.0.0" />
<PackageReference Include="Ling.AutoInject"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Ling.AutoInject --version 1.0.0
#r "nuget: Ling.AutoInject, 1.0.0"
#:package Ling.AutoInject@1.0.0
#addin nuget:?package=Ling.AutoInject&version=1.0.0
#tool nuget:?package=Ling.AutoInject&version=1.0.0
Ling.AutoInject
Ling.AutoInject provides attribute-driven registration helpers and integrates with a source generator to emit IServiceCollection extension methods that register services discovered via attributes at compile time.
Features
- Attributes:
SingletonService,ScopedService,TransientServicefor simple, declarative registration. - Optional service typing and keyed registration support.
- Configurable generated method name, host class and namespace through an assembly-level
AutoInjectConfigattribute. - Complementary analyzers to surface common mistakes and invalid configurations in the IDE.
Installation
via .NET CLI:
dotnet add package Ling.AutoInject
via Package Manager Console:
Install-Package Ling.AutoInject
Usage
Decorate implementation types:
using Ling.AutoInject; [SingletonService] public class MyService { } [ScopedService(typeof(IFoo))] public class MyService : IFoo { } [TransientService(ServiceKey = "k1")] public class MyService { }(Optional) Configure generator output naming:
[assembly: Ling.AutoInject.AutoInjectConfig( MethodName = "AddCustomServices", ClassName = "ServiceExtensions", Namespace = "MyNamespace")]Call the generated extension in
Program/Startup:services.Add[MyAssembly]Services(); // or services.AddCustomServices();
Notes
- If no service type is specified, the implementation type is registered as itself.
- If a service type is specified, the generator registers the mapping from service interface to implementation.
- Keyed registration requires the DI Abstractions package to support keyed APIs; analyzers warn when unsupported.
Planned features
- Options binding: future work will add attribute-driven registration and configuration binding for options classes (
IOptions<T>), including section binding.
Contributing
- PRs and issues welcome. Include tests for analyzer/generator changes.
License
- MIT License.
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 3.1
-
.NETStandard 2.0
-
.NETStandard 2.1
-
net10.0
-
net5.0
-
net6.0
-
net7.0
-
net8.0
-
net9.0
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Ling.AutoInject:
| Package | Downloads |
|---|---|
|
Ling.AutoInject.Options
Options registration contracts for Ling.AutoInject. |
GitHub repositories
This package is not used by any popular GitHub repositories.