AtlasSync.DependencyInjection 1.0.3

dotnet add package AtlasSync.DependencyInjection --version 1.0.3
                    
NuGet\Install-Package AtlasSync.DependencyInjection -Version 1.0.3
                    
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="AtlasSync.DependencyInjection" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AtlasSync.DependencyInjection" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="AtlasSync.DependencyInjection" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AtlasSync.DependencyInjection --version 1.0.3
                    
#r "nuget: AtlasSync.DependencyInjection, 1.0.3"
                    
#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.
#:package AtlasSync.DependencyInjection@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AtlasSync.DependencyInjection&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=AtlasSync.DependencyInjection&version=1.0.3
                    
Install as a Cake Tool

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

  1. Create a class that extends ServiceRegistry to 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()));
        }
    }
    
  2. 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 ServiceRegistry implementations.

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last Updated
1.0.3 207 12/12/2024
1.0.2 165 12/12/2024
1.0.1 165 12/12/2024
1.0.0 174 12/11/2024