MeleagantDependencyScan 1.1.0

dotnet add package MeleagantDependencyScan --version 1.1.0
NuGet\Install-Package MeleagantDependencyScan -Version 1.1.0
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.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MeleagantDependencyScan --version 1.1.0
#r "nuget: MeleagantDependencyScan, 1.1.0"
#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.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 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. 
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 181 4/4/2024
1.0.1 140 2/22/2024
1.0.0 81 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.