MeleagantDependencyScan 1.1.0
dotnet add package MeleagantDependencyScan --version 1.1.0
NuGet\Install-Package MeleagantDependencyScan -Version 1.1.0
<PackageReference Include="MeleagantDependencyScan" Version="1.1.0" />
paket add MeleagantDependencyScan --version 1.1.0
#r "nuget: MeleagantDependencyScan, 1.1.0"
// Install MeleagantDependencyScan as a Cake Addin #addin nuget:?package=MeleagantDependencyScan&version=1.1.0 // Install MeleagantDependencyScan as a Cake Tool #tool nuget:?package=MeleagantDependencyScan&version=1.1.0
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 :
using MeleagantDependencyScan.Attributes;
[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 :
using MeleagantDependencyScan.Attributes;
[MeleagantInjection(LifeTime = ServiceLifetime.Transient)]
public class AuthService
{
// Your auth logic
}
Scoped use case without interfaces :
using MeleagantDependencyScan.Attributes;
[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.
using MeleagantDependencyScan.Attributes;
[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
using MeleagantDependencyScan.Extensions;
// Some logic ...
// Use this instruction
builder.Services.ScanAssemblies("MySuperAssembly");
// Before this one
var app = builder.Build();
Multiple assembly
using MeleagantDependencyScan.Extensions;
// Some logic ...
// 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 | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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 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 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. |
-
net5.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
-
net6.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
-
net7.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
-
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.