Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add extensions to add multiple open behaviors.
  • Loading branch information
Emopusta committed Aug 28, 2024
commit b106f2d1bafe690377e75c28b19a61cac42010d9
32 changes: 32 additions & 0 deletions src/MediatR/MicrosoftExtensionsDI/MediatrServiceConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Reflection;
using MediatR;
using MediatR.Entities;
using MediatR.NotificationPublishers;
using MediatR.Pipeline;
using MediatR.Registration;
Expand Down Expand Up @@ -222,6 +223,37 @@ public MediatRServiceConfiguration AddOpenBehavior(Type openBehaviorType, Servic
return this;
}

/// <summary>
/// Registers multiple open behavior types against the <see cref="IPipelineBehavior{TRequest,TResponse}"/> open generic interface type
/// </summary>
/// <param name="openBehaviorTypes">An open generic behavior type list includes multiple open generic behavior types.</param>
/// <param name="serviceLifetime">Optional service lifetime, defaults to <see cref="ServiceLifetime.Transient"/>.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddOpenBehaviors(IEnumerable<Type> openBehaviorTypes, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
foreach (var openBehaviorType in openBehaviorTypes)
{
AddOpenBehavior(openBehaviorType, serviceLifetime);
}

return this;
}

/// <summary>
/// Registers open behaviors against the <see cref="IPipelineBehavior{TRequest,TResponse}"/> open generic interface type
/// </summary>
/// <param name="openBehaviors">An open generic behavior list includes multiple <see cref="OpenBehavior"/> open generic behaviors.</param>
/// <returns>This</returns>
public MediatRServiceConfiguration AddOpenBehaviors(IEnumerable<OpenBehavior> openBehaviors)
{
foreach (var openBehavior in openBehaviors)
{
AddOpenBehavior(openBehavior.OpenBehaviorType!, openBehavior.ServiceLifetime);
}

return this;
}

/// <summary>
/// Register a closed stream behavior type
/// </summary>
Expand Down