DependencyInjection.ReflectionExtensions 2025.6.11

There is a newer version of this package available.
See the version list below for details.
dotnet add package DependencyInjection.ReflectionExtensions --version 2025.6.11
                    
NuGet\Install-Package DependencyInjection.ReflectionExtensions -Version 2025.6.11
                    
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="DependencyInjection.ReflectionExtensions" Version="2025.6.11" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DependencyInjection.ReflectionExtensions" Version="2025.6.11" />
                    
Directory.Packages.props
<PackageReference Include="DependencyInjection.ReflectionExtensions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DependencyInjection.ReflectionExtensions --version 2025.6.11
                    
#r "nuget: DependencyInjection.ReflectionExtensions, 2025.6.11"
                    
#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.
#:package DependencyInjection.ReflectionExtensions@2025.6.11
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DependencyInjection.ReflectionExtensions&version=2025.6.11
                    
Install as a Cake Addin
#tool nuget:?package=DependencyInjection.ReflectionExtensions&version=2025.6.11
                    
Install as a Cake Tool

DotNet.DependencyInjection

Biblioteca que facilita la configuración de la inyección de dependencias en aplicaciones ASP.NET Core, permitiendo el registro automático de servicios desde un ensamblado.

Características

  • Registro automático de servicios
  • Soporte para múltiples ciclos de vida
  • Filtros personalizados
  • Logging configurable
  • Manejo de tipos genéricos
  • Integración con ASP.NET Core
  • Registro de servicios individuales o por interfaz

Instalación

El componente se puede instalar como un paquete NuGet:

dotnet add package DeveloperKit.DependencyInjection

Requisitos

  • .NET Core 3.1 o superior
  • ASP.NET Core
  • Visual Studio 2019 o superior

Uso Básico

Configuración Simple

public void ConfigureServices(IServiceCollection services)
{
    // Registrar servicios desde el ensamblado actual
    services.BindFromAssembly(Assembly.GetExecutingAssembly());
}

Configuración Avanzada

public void ConfigureServices(IServiceCollection services)
{
    // Configuración con todas las opciones
    services.BindFromAssembly(
        assembly: Assembly.GetExecutingAssembly(),
        filter: type => !type.Name.Contains("Test"), // Filtrar tipos
        logger: message => Console.WriteLine(message), // Logger personalizado
        onlyClass: false, // Registrar solo clases o también interfaces
        lifetime: ServiceLifetime.Scoped // Ciclo de vida
    );
}

Parámetros de Configuración

assembly

  • Ensamblado del cual se registrarán los servicios
  • Ejemplo: Assembly.GetExecutingAssembly()

filter

  • Función que filtra qué tipos se registran
  • Por defecto: null (registra todos los tipos)
  • Ejemplo: type => type.Name.Contains("Service")

logger

  • Función para registrar mensajes
  • Por defecto: null
  • Ejemplo: message => Console.WriteLine(message)

onlyClass

  • Si es true, registra solo las clases
  • Si es false, registra clases e interfaces
  • Por defecto: false

lifetime

  • Ciclo de vida del servicio
  • Opciones: Scoped (por defecto), Singleton, Transient

Ejemplos de Uso

Registro Básico

// Servicio concreto
public class MyService : IMyService
{
    public void DoWork() {}
}

// Configuración
services.BindFromAssembly(
    assembly: Assembly.GetExecutingAssembly(),
    filter: type => type.Name.EndsWith("Service")
);

Registro con Logging

// Configuración con logging
services.BindFromAssembly(
    assembly: Assembly.GetExecutingAssembly(),
    logger: message =>
    {
        Console.WriteLine($"[DI] {message}");
    }
);

Registro con Ciclo de Vida Específico

// Configuración con ciclo de vida Singleton
services.BindFromAssembly(
    assembly: Assembly.GetExecutingAssembly(),
    lifetime: ServiceLifetime.Singleton
);

Mejores Prácticas

  1. Nomenclatura

    • Usar sufijos consistentes para los servicios (ej: Service, Repository)
    • Nombrar interfaces con prefijo I (ej: IMyService)
  2. Filtros

    • Usar filtros para evitar registros innecesarios
    • Filtrar tipos de prueba o de desarrollo
  3. Logging

    • Implementar logging para debugging
    • Usar diferentes niveles de logging
  4. Ciclos de Vida

    • Usar Scoped para servicios por solicitud
    • Usar Singleton para servicios únicos
    • Usar Transient para servicios por instancia

Soporte

Para reportar errores o solicitar características, por favor abre un issue en el repositorio de GitHub.

Licencia

Este proyecto está bajo licencia MIT. Consulta el archivo LICENSE para más detalles.

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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Framework net48 is compatible.  net481 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
2025.8.19 132 8/19/2025
2025.8.13 128 8/13/2025
2025.7.13 159 7/14/2025
2025.6.12 300 6/11/2025
2025.6.11 294 6/11/2025
2025.5.24 107 5/24/2025
2025.5.23 75 5/23/2025
2025.5.16 239 5/15/2025
2025.5.15 232 5/15/2025
2025.5.14 236 5/14/2025
2025.5.13 244 5/13/2025