MeleagantDependencyScan 1.0.1
See the version list below for details.
dotnet add package MeleagantDependencyScan --version 1.0.1
NuGet\Install-Package MeleagantDependencyScan -Version 1.0.1
<PackageReference Include="MeleagantDependencyScan" Version="1.0.1" />
paket add MeleagantDependencyScan --version 1.0.1
#r "nuget: MeleagantDependencyScan, 1.0.1"
// Install MeleagantDependencyScan as a Cake Addin #addin nuget:?package=MeleagantDependencyScan&version=1.0.1 // Install MeleagantDependencyScan as a Cake Tool #tool nuget:?package=MeleagantDependencyScan&version=1.0.1
MeleagantDependencyScan
The purpose of this library is to provide tools to facilitate dependency injection when using dotnet.
How to use
First : Decorate needed classes
Singleton (without interfaces)
The simplest use case is the singleton without interfaces :
[MeleagantInjection] // By default LifeTime is intialized to Singleton, so there's no need to specify it in this case
public class AuthService
{
// Your auth logic
}
Transient or Scoped (without interfaces)
Transient use case without interfaces :
[MeleagantInjection(LifeTime = ServiceLifetime.Transient)]
public class AuthService
{
// Your auth logic
}
Scoped use case without interfaces :
[MeleagantInjection(LifeTime = ServiceLifetime.Scoped)]
public class AuthService
{
// Your auth logic
}
With interfaces (Scoped)
Let's assume that we have an IAuthService
interface
public interface IAuthService
{
string Register(RegisterDto registerDto);
}
And a custom auth service that implement this interface here it's MySuperAuthService
. And we needed it with the scoped life time.
[MeleagantInjection(LifeTime = ServiceLifetime.Scoped, VisibleFromInterface = true, VisibleAs = [typeof(IAuthService)])]
public class MySuperAuthService : IAuthService
{
// Your auth logic
public string Register(RegisterDto registerDto)
{
// Register logic
}
}
Then : Scan your assemblies
To register your classes in the ServiceCollection
you must add the ScanAssemblies
instruction to your Program.cs
Single assembly
// Use this instruction
builder.Services.ScanAssemblies("MySuperAssembly");
// Before this one
var app = builder.Build();
Multiple assembly
// Use this instruction
builder.Services.ScanAssemblies("MySuperAssembly", "MyAwesomeAssembly");
// Before this one
var app = builder.Build();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
First version. Add the attribute identifying the component to be added to the extension's ServiceCollection in order to scan the Assembly.