ServiceRegistration 10.0.1
dotnet add package ServiceRegistration --version 10.0.1
NuGet\Install-Package ServiceRegistration -Version 10.0.1
<PackageReference Include="ServiceRegistration" Version="10.0.1" />
<PackageVersion Include="ServiceRegistration" Version="10.0.1" />
<PackageReference Include="ServiceRegistration" />
paket add ServiceRegistration --version 10.0.1
#r "nuget: ServiceRegistration, 10.0.1"
#:package ServiceRegistration@10.0.1
#addin nuget:?package=ServiceRegistration&version=10.0.1
#tool nuget:?package=ServiceRegistration&version=10.0.1
Service Registration Utils
A .NET library that simplifies dependency injection service registration through attributes. Instead of manually registering each service in your Program.cs, simply decorate your classes with lifetime attributes and let the library handle the registration automatically.
Installation
Install the package from NuGet:
dotnet add package ServiceRegistration
Usage
- Add attributes to your services:
[TransientService]
public class EmailService { }
[ScopedService(typeof(IUserService))]
public class UserService : IUserService { }
[SingletonService]
public class ConfigurationService { }
[HostedService]
public class BackgroundTaskService : BackgroundService { }
- Register all attributed services:
using ServiceRegistration;
var builder = WebApplication.CreateBuilder(args);
// Register all attributed services in the current assembly
builder.Services.AddAppServices(System.Reflection.Assembly.GetExecutingAssembly());
var app = builder.Build();
app.Run();
Available Attributes
[TransientService]- Equivalent toservices.AddTransient<T>()[TransientService(typeof(I))]- Equivalent toservices.AddTransient<I, T>()[ScopedService]- Equivalent toservices.AddScoped<T>()[ScopedService(typeof(I))]- Equivalent toservices.AddScoped<I, T>()[SingletonService]- Equivalent toservices.AddSingleton<T>()[SingletonService(typeof(I))]- Equivalent toservices.AddSingleton<I, T>()[HostedService]- Equivalent toservices.AddHostedService<T>()
Singleton, Transient, and Scoped attributes support optional interface binding:
[TransientService(typeof(IEmailService))]
public class EmailService : IEmailService { }
For more information about service lifetimes, see the Microsoft documentation.
Repository
Visit the GitHub repository for source code and issues.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.