AtlasSync.DependencyInjection
1.0.3
dotnet add package AtlasSync.DependencyInjection --version 1.0.3
NuGet\Install-Package AtlasSync.DependencyInjection -Version 1.0.3
<PackageReference Include="AtlasSync.DependencyInjection" Version="1.0.3" />
<PackageVersion Include="AtlasSync.DependencyInjection" Version="1.0.3" />
<PackageReference Include="AtlasSync.DependencyInjection" />
paket add AtlasSync.DependencyInjection --version 1.0.3
#r "nuget: AtlasSync.DependencyInjection, 1.0.3"
#:package AtlasSync.DependencyInjection@1.0.3
#addin nuget:?package=AtlasSync.DependencyInjection&version=1.0.3
#tool nuget:?package=AtlasSync.DependencyInjection&version=1.0.3
AtlasSync.DependencyInjection
AtlasSync.DependencyInjection is a library designed to simplify dependency injection and application configuration in ASP.NET Core projects. It uses the concept of ServiceRegistry to enable modular and assembly-based configuration.
Installation
Add the package to your project via NuGet:
dotnet add package AtlasSync.DependencyInjection
Getting Started
Create a class that extends
ServiceRegistryto define your dependency injection logic:using System.Reflection; using AtlasSync.DependencyInjection; /// <summary> /// Service registrant for configuring MediatR-related services. /// </summary> public sealed class MediatorRegistrant : ServiceRegistry { public override void ConfigureServices(WebApplicationBuilder builder) { base.ConfigureServices(builder); // Add MediatR services and register handlers from the executing assembly builder.Services.AddMediatR(x => x.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly())); } }In your
Program.cs, use the provided extension methods to configure services and the application:using AtlasSync.DependencyInjection; var builder = WebApplication.CreateBuilder(args); // Configure services from registrants found in the assembly builder.ConfigureServicesFromAssembly(Assembly.GetExecutingAssembly()); var app = builder.Build(); // Configure the application using registrants app.ConfigureApplicationFromAssembly(Assembly.GetExecutingAssembly()); app.MapGet("/", () => "Hello, World!"); app.Run();
How It Works
ServiceRegistry
The ServiceRegistry is an abstract base class that you can extend to define your service configuration logic. It includes two overridable methods:
ConfigureServices(WebApplicationBuilder builder): Use this method to register services with the dependency injection container.Configure(WebApplication app): Use this method to configure the application pipeline.
Assembly Scanning
The library scans the executing assembly for non-abstract implementations of ServiceRegistry and automatically invokes their configuration methods.
Features
- Simplifies dependency injection setup.
- Modular design for easy scalability.
- Automatic assembly scanning for
ServiceRegistryimplementations.
Example Use Cases
- Registering services for libraries like MediatR, AutoMapper, or custom services.
- Modularizing service and middleware configuration in large projects.
Contributing
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
License
This package is licensed under the MIT License. See the LICENSE file for more details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. net10.0 was computed. 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. |
-
net9.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.