NetCore.AutoRegisterDi 1.1.0

Extension method to find/register classes in an assembly into Microsoft.Extensions.DependencyInjection

Install-Package NetCore.AutoRegisterDi -Version 1.1.0
dotnet add package NetCore.AutoRegisterDi --version 1.1.0
<PackageReference Include="NetCore.AutoRegisterDi" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetCore.AutoRegisterDi --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

NetCore.AutoRegisterDi

This NuGet library contains an extension method to scan an assemby and register all the public classes against their implemented interfaces(s) into the Microsoft.Extensions.DependencyInjection dependency injection provider.

I have written a simple version of AutoFac's RegisterAssemblyTypes method that works directly with Microsoft's DI provider. Here are an example of me using this with ASP.NET Core

Example 1 - scan the calling assembly
public void ConfigureServices(IServiceCollection services)
{
   //... other configure code removed

   service.RegisterAssemblyPublicNonGenericClasses()
     .Where(c => c.Name.EndsWith("Service"))
     .AsPublicImplementedInterfaces();
Example 2 - scaning multiple assemblies
public void ConfigureServices(IServiceCollection services)
{
   //... other configure code removed

   var assembliesToScan = new [] 
   {
        Assembly.GetExecutingAssembly(),
        Assembly.GetAssembly(typeof(MyServiceInAssembly1)),
        Assembly.GetAssembly(typeof(MyServiceInAssembly2))
   };   

   service.RegisterAssemblyPublicNonGenericClasses(assembliesToScan)
     .Where(c => c.Name.EndsWith("Service"))
     .AsPublicImplementedInterfaces(); 

Licence: MIT.

See this article for a bigger coverage of Microsoft DI and the use of this library in real applications.

NetCore.AutoRegisterDi

This NuGet library contains an extension method to scan an assemby and register all the public classes against their implemented interfaces(s) into the Microsoft.Extensions.DependencyInjection dependency injection provider.

I have written a simple version of AutoFac's RegisterAssemblyTypes method that works directly with Microsoft's DI provider. Here are an example of me using this with ASP.NET Core

Example 1 - scan the calling assembly
public void ConfigureServices(IServiceCollection services)
{
   //... other configure code removed

   service.RegisterAssemblyPublicNonGenericClasses()
     .Where(c => c.Name.EndsWith("Service"))
     .AsPublicImplementedInterfaces();
Example 2 - scaning multiple assemblies
public void ConfigureServices(IServiceCollection services)
{
   //... other configure code removed

   var assembliesToScan = new [] 
   {
        Assembly.GetExecutingAssembly(),
        Assembly.GetAssembly(typeof(MyServiceInAssembly1)),
        Assembly.GetAssembly(typeof(MyServiceInAssembly2))
   };   

   service.RegisterAssemblyPublicNonGenericClasses(assembliesToScan)
     .Where(c => c.Name.EndsWith("Service"))
     .AsPublicImplementedInterfaces(); 

Licence: MIT.

See this article for a bigger coverage of Microsoft DI and the use of this library in real applications.

Release Notes

New Feature: if no assembly is provided it scans the assembly that called the method.

Showing the top 1 GitHub repositories that depend on NetCore.AutoRegisterDi:

Repository Stars
JonPSmith/EfCore.GenericBizRunner
Library to run business logic when using Entity Framework Core for database accesses

Version History

Version Downloads Last updated
1.1.0 8,682 8/26/2019
1.0.0 63,931 6/16/2018