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" />
<PackageReference Include="DomainRelay.DependencyInjection" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=DomainRelay.DependencyInjection&version=3.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DomainRelay.DependencyInjection
DI integration for DomainRelay.
Install
DomainRelay.AbstractionsDomainRelayDomainRelay.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);
}
);
Recommended registration (ASP.NET Core)
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 | 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- DomainRelay (>= 3.1.3)
- DomainRelay.Abstractions (>= 3.1.3)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.