diff --git a/src/MediatR/Entities/OpenBehavior.cs b/src/MediatR/Entities/OpenBehavior.cs
index e7201da3..71088415 100644
--- a/src/MediatR/Entities/OpenBehavior.cs
+++ b/src/MediatR/Entities/OpenBehavior.cs
@@ -1,20 +1,53 @@
-using System;
using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Linq;
namespace MediatR.Entities;
///
-/// Creates open behavior entity.
+/// Represents a registration entity for pipeline behaviors with a specified service lifetime.
///
public class OpenBehavior
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The type of the pipeline behavior to register.
+ /// The lifetime of the registered service. Defaults to Transient.
+ /// Thrown if the specified type does not implement IPipelineBehavior.
+ /// Thrown if is null.
public OpenBehavior(Type openBehaviorType, ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
+ ValidatePipelineBehaviorType(openBehaviorType);
OpenBehaviorType = openBehaviorType;
ServiceLifetime = serviceLifetime;
}
- public Type? OpenBehaviorType { get; }
+ ///
+ /// The type of the open behavior.
+ ///
+ public Type OpenBehaviorType { get; }
+
+ ///
+ /// The service lifetime of the open behavior.
+ ///
public ServiceLifetime ServiceLifetime { get; }
-
+ ///
+ /// Validates whether the specified type implements the interface.
+ ///
+ /// The type to validate.
+ /// Thrown if the type does not implement .
+ /// Thrown if is null.
+ private static void ValidatePipelineBehaviorType(Type openBehaviorType)
+ {
+ if (openBehaviorType == null) throw new ArgumentNullException(nameof(openBehaviorType));
+
+ bool isPipelineBehavior = openBehaviorType.GetInterfaces()
+ .Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IPipelineBehavior<,>));
+
+ if (!isPipelineBehavior)
+ {
+ throw new InvalidOperationException($"The type \"{openBehaviorType.Name}\" must implement IPipelineBehavior<,> interface.");
+ }
+ }
}
\ No newline at end of file