NetCore.AutoRegisterDi
2.0.0
See the version list below for details.
dotnet add package NetCore.AutoRegisterDi --version 2.0.0
NuGet\Install-Package NetCore.AutoRegisterDi -Version 2.0.0
<PackageReference Include="NetCore.AutoRegisterDi" Version="2.0.0" />
paket add NetCore.AutoRegisterDi --version 2.0.0
#r "nuget: NetCore.AutoRegisterDi, 2.0.0"
// Install NetCore.AutoRegisterDi as a Cake Addin #addin nuget:?package=NetCore.AutoRegisterDi&version=2.0.0 // Install NetCore.AutoRegisterDi as a Cake Tool #tool nuget:?package=NetCore.AutoRegisterDi&version=2.0.0
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.
Version 2 update: New attributes for defining the ServiceLifetime
of your classes, e.g. adding the [RegisterAsScoped]
attribute to a class will mean its ServiceLifetime
in the DI will be set to Scoped
.
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.
Product | Versions 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 was computed. 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 was computed. 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. |
.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. |
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection (>= 2.1.0)
NuGet packages (24)
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 |
|
AlphaReds.Core.Common
Common class for AlphaReds project |
|
Dsquares-SharedHelper.API
An API project pacakge to simplify the creation of new projects and centralize repeated logic. -Based on clean architect |
|
Relay.Core.Plugins.Microservices
Plugins available for the Core framework |
GitHub repositories (6)
Showing the top 5 popular GitHub repositories that depend on NetCore.AutoRegisterDi:
Repository | Stars |
---|---|
JonPSmith/AuthPermissions.AspNetCore
This library provides extra authorization and multi-tenant features to an ASP.NET Core application.
|
|
JonPSmith/EfCoreinAction-SecondEdition
Supporting repo to go with book "Entity Framework Core in Action", second edition
|
|
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
|
|
CnGal/CnGalWebSite
CnGal是一个非营利性的,立志于收集整理国内制作组创作的中文Galgame/AVG的介绍、攻略、评测、感想等内容的资料性质的网站。
|
New Feature: You can now set what ServiceLifetime your class has via Attributes - see README file.