DependencyInjection.ReflectionExtensions
2025.6.11
.NET 8.0
This package targets .NET 8.0. The package is compatible with this framework or higher.
.NET Framework 4.8
This package targets .NET Framework 4.8. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
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" />
<PackageReference Include="DependencyInjection.ReflectionExtensions" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=DependencyInjection.ReflectionExtensions&version=2025.6.11
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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
Nomenclatura
- Usar sufijos consistentes para los servicios (ej:
Service
,Repository
) - Nombrar interfaces con prefijo
I
(ej:IMyService
)
- Usar sufijos consistentes para los servicios (ej:
Filtros
- Usar filtros para evitar registros innecesarios
- Filtrar tipos de prueba o de desarrollo
Logging
- Implementar logging para debugging
- Usar diferentes niveles de logging
Ciclos de Vida
- Usar
Scoped
para servicios por solicitud - Usar
Singleton
para servicios únicos - Usar
Transient
para servicios por instancia
- Usar
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 | 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. 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.
-
.NETFramework 4.8
- CoreInterfaces (>= 2025.6.11)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.5)
-
net8.0
- CoreInterfaces (>= 2025.6.11)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.5)
-
net9.0
- CoreInterfaces (>= 2025.6.11)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.