MeleagantDependencyScan 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package MeleagantDependencyScan --version 1.0.1                
NuGet\Install-Package MeleagantDependencyScan -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MeleagantDependencyScan" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MeleagantDependencyScan --version 1.0.1                
#r "nuget: MeleagantDependencyScan, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.1.0 402 4/4/2024
1.0.1 182 2/22/2024
1.0.0 119 2/22/2024

First version. Add the attribute identifying the component to be added to the extension's ServiceCollection in order to scan the Assembly.