SnappyLib.Gen.AutoInject
3.0.6
dotnet add package SnappyLib.Gen.AutoInject --version 3.0.6
NuGet\Install-Package SnappyLib.Gen.AutoInject -Version 3.0.6
<PackageReference Include="SnappyLib.Gen.AutoInject" Version="3.0.6" />
<PackageVersion Include="SnappyLib.Gen.AutoInject" Version="3.0.6" />
<PackageReference Include="SnappyLib.Gen.AutoInject" />
paket add SnappyLib.Gen.AutoInject --version 3.0.6
#r "nuget: SnappyLib.Gen.AutoInject, 3.0.6"
#:package SnappyLib.Gen.AutoInject@3.0.6
#addin nuget:?package=SnappyLib.Gen.AutoInject&version=3.0.6
#tool nuget:?package=SnappyLib.Gen.AutoInject&version=3.0.6
Generator Documentation
The purpose of this generator is to automatically register types into the Dependency Injection (DI) container based on the attributes applied to the class. These attributes determine the lifetime of the registered service and are as follows:
Supported Lifetime Attributes
[HostedService]Registers the class as a hosted background service that implements theIHostedServiceinterface.[Transient]
Registers the class as a transient service, meaning a new instance is created every time it's requested.[Scoped]
Registers the class as a scoped service, meaning a new instance is created for each scope (e.g., per HTTP request in a web application).[Singleton]
Registers the class as a singleton service, meaning only one instance exists for the lifetime of the application.
Behavior
When a type is annotated with one of the supported attributes, the generator will:
- Register the type itself with the DI container using the specified lifetime.
- Register all interfaces the type implements with the DI container, resolving to the annotated type and using the same specified lifetime.
Usage
To use this, annotate your service class with one of the lifetime attributes ([HostedService], [Transient], [Scoped], or [Singleton]) and implement any required interfaces. The generator will handle the registration automatically.
Example
[Transient]
public class MyService : IMyService
{
// Implementation...
}
In this example:
- The generator will register
MyServiceitself as a transient service. - The generator will also register the
IMyServiceinterface as a transient service and resolve it toMyService.
Learn more about Target Frameworks and .NET Standard.
-
.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 |
|---|---|---|
| 3.0.6 | 204 | 3/13/2025 |