NetCore.AutoRegisterDi 1.1.0

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

There is a newer version of this package available.
See the version list below for details.
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.
#r "nuget: NetCore.AutoRegisterDi, 1.1.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install NetCore.AutoRegisterDi as a Cake Addin
#addin nuget:?package=NetCore.AutoRegisterDi&version=1.1.0

// Install NetCore.AutoRegisterDi as a Cake Tool
#tool nuget:?package=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.

NuGet packages (10)

Showing the top 5 NuGet packages that depend on NetCore.AutoRegisterDi:

Package Downloads
Relay.Microservices
A microservice framework built for .NET Core
Relay.Microservices.Testing
A microservice testing framework built for .NET Core
Relay.Core.Plugins.Microservices
Plugins available for the Core framework
Relay.Core.Microservices.Testing
A microservice testing framework built for .NET Core
Relay.Core.Microservices
A microservice framework built for .NET Core

GitHub repositories (3)

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

Repository Stars
JonPSmith/PermissionAccessControl2
Version 2 of example application to go with articles on feature and data authorization
JonPSmith/EfCore.GenericBizRunner
Library to run business logic when using Entity Framework Core for database accesses
JonPSmith/EfCoreinAction-SecondEdition
Supporting repo to go with book "Entity Framework Core in Action", second edition

Version History

Version Downloads Last updated
2.1.0 86,735 10/6/2020
2.0.0 101,436 5/9/2020
1.1.0 273,524 8/26/2019
1.0.0 136,337 6/16/2018