CastelloBranco.ServiceRegistrationGenerator
1.0.50
See the version list below for details.
dotnet add package CastelloBranco.ServiceRegistrationGenerator --version 1.0.50
NuGet\Install-Package CastelloBranco.ServiceRegistrationGenerator -Version 1.0.50
<PackageReference Include="CastelloBranco.ServiceRegistrationGenerator" Version="1.0.50" />
paket add CastelloBranco.ServiceRegistrationGenerator --version 1.0.50
#r "nuget: CastelloBranco.ServiceRegistrationGenerator, 1.0.50"
// Install CastelloBranco.ServiceRegistrationGenerator as a Cake Addin #addin nuget:?package=CastelloBranco.ServiceRegistrationGenerator&version=1.0.50 // Install CastelloBranco.ServiceRegistrationGenerator as a Cake Tool #tool nuget:?package=CastelloBranco.ServiceRegistrationGenerator&version=1.0.50
ServiceRegistrationGenerator ServiceRegistrationGenerator is a source generator for .NET projects that automatically registers services into the dependency injection container based on custom attributes. It simplifies the process of setting up DI by eliminating manual service registration.
Table of Contents Installation Usage Attributes Example License Contributing Support Installation You can install ServiceRegistrationGenerator via NuGet:
bash Copiar código dotnet add package ServiceRegistrationGenerator Alternatively, you can find it on the NuGet website.
Usage The ServiceRegistrationGenerator automatically registers services annotated with specific attributes ([RegisterAsSingleton], [RegisterAsTransient], etc.) into the DI container.
Add Attributes: Add custom attributes to your services to specify their DI lifetime.
Build the Project: The generator runs during compilation, generating a helper file that registers each annotated service.
Supported Attributes Attribute Lifetime Description [RegisterAsSingleton] Singleton Registers the service as a singleton. [RegisterAsTransient] Transient Registers the service as a transient instance.
Generated Code The generator produces a helper file, AppServicesHelper.g.cs, which includes a method to register all services in the DI container. This file is automatically updated whenever new attributes are added or modified.
Example
- Define Services and Use Attributes In your project, define interfaces and classes and use RegisterAsSingleton, RegisterAsTransient, or RegisterAsScoped attributes as needed.
Copiar código
using ServiceRegistrationGenerator;
[RegisterAsSingleton]
public interface IMySingletonService { }
public class MySingletonService : IMySingletonService { }
[RegisterAsTransient]
public interface IMyTransientService { }
public class MyTransientService : IMyTransientService { }
- Use the Generated Helper The generator will create a helper file with a RegisterServices method, which you can call during application startup:
public class Program
{
public static void Main(string[] args)
{
var services = new ServiceCollection();
AppServicesHelper.RegisterServices(services);
}
}
License This project is licensed under the MIT License - see the LICENSE file for details.
Contributing Contributions are welcome! Please open an issue or submit a pull request on the GitHub repository.
Support For support or questions, please open an issue on the GitHub repository.
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. |
.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
- 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.