sorovi.DependencyInjection.AutoRegister 1.0.4

dotnet add package sorovi.DependencyInjection.AutoRegister --version 1.0.4
NuGet\Install-Package sorovi.DependencyInjection.AutoRegister -Version 1.0.4
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="sorovi.DependencyInjection.AutoRegister" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add sorovi.DependencyInjection.AutoRegister --version 1.0.4
#r "nuget: sorovi.DependencyInjection.AutoRegister, 1.0.4"
#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 sorovi.DependencyInjection.AutoRegister as a Cake Addin
#addin nuget:?package=sorovi.DependencyInjection.AutoRegister&version=1.0.4

// Install sorovi.DependencyInjection.AutoRegister as a Cake Tool
#tool nuget:?package=sorovi.DependencyInjection.AutoRegister&version=1.0.4

sorovi.DependencyInjection.AutoRegister

NuGet NuGet

You are tired from adding every service to the DI Container(ASP.Net)? Great, this library is exactly what you are looking for. It searches for a couple of attributes on your classes and will add them automatically!


Examples

Quickstart

just call RegisterServices inside of the ConfigureServices-method` and it will search for all classes in the entry assembly for the following attributes:

  • TransientService
  • ScopedService
  • SingletonService
  • BackgroundService
[TransientService(typeof(IMyService))]
public class MyService : IMyService { }
public void ConfigureServices(IServiceCollection serviceCollection)
{
   
   serviceCollection.RegisterServices()
   // ...
}
search in multiple assemblies
serviceCollection.RegisterServices(
    Assembly.GetEntryAssembly(),
    typeof(ServiceInAnotherAssembly).Assembly
)
with additional filter

you can easily add a filter to only search in certain classes. You'll only need this if the default is not strict enough

serviceCollection.RegisterServices(configure => configure
    .WithTypeFilter( type => type.Name.EndsWith("Service"))
);

Benchmark

BenchmarkDotNet=v0.13.2, OS=macOS 13.0.1 (22A400) [Darwin 22.1.0]
Intel Core i7-9750H CPU 2.60GHz, 1 CPU, 12 logical and 6 physical cores
.NET SDK=6.0.202
[Host] : .NET 6.0.4 (6.0.422.16404), X64 RyuJIT AVX2
DefaultJob : .NET 6.0.4 (6.0.422.16404), X64 RyuJIT AVX2

Method Mean Error StdDev Ratio RatioSD Gen0 Allocated Alloc Ratio
ManuallyAdd 314.3 ns 6.36 ns 9.12 ns 1.00 0.00 0.1030 648 B 1.00
AutoRegister 26,107.7 ns 507.60 ns 498.53 ns 82.34 3.18 0.5493 3579 B 5.52

Note: depends highly on the used assembly

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.0.4 280 12/20/2023
1.0.3 15,583 9/14/2023
1.0.2 651 12/17/2022
1.0.1 16,487 4/10/2022
1.0.0 12,067 10/14/2021
0.1.1 43,297 1/26/2021
0.1.0 308 1/26/2021