DomainRelay.DependencyInjection 3.1.3

dotnet add package DomainRelay.DependencyInjection --version 3.1.3
                    
NuGet\Install-Package DomainRelay.DependencyInjection -Version 3.1.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="DomainRelay.DependencyInjection" Version="3.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DomainRelay.DependencyInjection" Version="3.1.3" />
                    
Directory.Packages.props
<PackageReference Include="DomainRelay.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 DomainRelay.DependencyInjection --version 3.1.3
                    
#r "nuget: DomainRelay.DependencyInjection, 3.1.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 DomainRelay.DependencyInjection@3.1.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=DomainRelay.DependencyInjection&version=3.1.3
                    
Install as a Cake Addin
#tool nuget:?package=DomainRelay.DependencyInjection&version=3.1.3
                    
Install as a Cake Tool

DomainRelay.DependencyInjection

DI integration for DomainRelay.

Install

  • DomainRelay.Abstractions
  • DomainRelay
  • DomainRelay.DependencyInjection

Register

using DomainRelay.DependencyInjection;
using DomainRelay.Publish;

services.AddDomainRelay(
    configureOptions: o =>
    {
        // Notifications publish strategy (default: SequentialPublishStrategy)
        // o.PublishStrategy = new ParallelPublishStrategy();
    },
    configureRegistration: reg =>
    {
        // Assemblies containing IRequestHandler / INotificationHandler / IPipelineBehavior
        reg.Assemblies.Add(typeof(SomeHandler).Assembly);
    }
);

If your application contains open-generic handlers/behaviors (for example an AuditBehavior<TRequest, TResponse>), you may prefer to disable the built-in assembly scanning and register handlers yourself. This gives you full control over how open-generic implementations are mapped to open-generic service types.

using System.Reflection;
using DomainRelay.Abstractions;
using DomainRelay.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

public static class DomainRelaySetup
{
    public static IServiceCollection AddDomainRelayApp(this IServiceCollection services, params Assembly[] assemblies)
    {
        services.AddDomainRelay(
            configureOptions: _ => { },
            configureRegistration: reg =>
            {
                // We still pass assemblies (for future extensions), but disable built-in scanning.
                foreach (var a in assemblies)
                    reg.Assemblies.Add(a);

                // Recommended when you want deterministic registration of open-generics.
                reg.EnableAssemblyScanning = false;
            });

        RegisterDomainRelayHandlers(services, assemblies);
        return services;
    }

    private static void RegisterDomainRelayHandlers(IServiceCollection services, params Assembly[] assemblies)
    {
        // Scan concrete types.
        var allTypes = assemblies
            .Distinct()
            .SelectMany(SafeGetTypes)
            .Where(t => t is { IsAbstract: false, IsInterface: false })
            .ToArray();

        foreach (var impl in allTypes)
        {
            foreach (var itf in impl.GetInterfaces())
            {
                if (!itf.IsGenericType) continue;

                var def = itf.GetGenericTypeDefinition();
                if (def != typeof(IRequestHandler<,>) &&
                    def != typeof(INotificationHandler<>) &&
                    def != typeof(IPipelineBehavior<,>))
                {
                    continue;
                }

                // Closed generic interface -> register interface as-is.
                if (!itf.ContainsGenericParameters)
                {
                    services.TryAddEnumerable(ServiceDescriptor.Transient(itf, impl));
                    continue;
                }

                // Open-generic interface (e.g. IPipelineBehavior<,>) ->
                // register the open-generic service type to the open-generic implementation.
                if (!impl.IsGenericTypeDefinition)
                    continue;

                services.TryAddEnumerable(ServiceDescriptor.Transient(def, impl));
            }
        }
    }

    private static IEnumerable<Type> SafeGetTypes(Assembly a)
    {
        try { return a.GetTypes(); }
        catch (ReflectionTypeLoadException ex) { return ex.Types.Where(t => t is not null)!.Cast<Type>(); }
    }
}

Pipeline behaviors

You can register open-generic behaviors manually:

services.AddTransient(typeof(DomainRelay.Abstractions.IPipelineBehavior<,>), typeof(MyBehavior<,>));

Notes

  • Assembly scanning uses DI enumerable registration patterns to avoid common duplicates when the same types are registered multiple times.
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.

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
3.1.3 47 5/25/2026
3.1.2 40 5/24/2026
3.1.1 188 4/26/2026
3.1.0 98 4/25/2026
3.0.1 96 4/24/2026
3.0.0 95 4/24/2026
2.0.1 395 3/6/2026
2.0.0 99 3/5/2026
1.0.2-alpha.4 63 3/5/2026
1.0.1-alpha.4 59 3/5/2026
1.0.0 106 3/5/2026