Title: Add AddQueryPipelineBehavior<T>() for closed generic query behaviors
Labels: bug, mediator
Body:
Problem
MediatorOptions provides closed-generic registration for commands and notifications:
AddCommandPipelineBehavior<TBehavior>() -- closed generic
AddNotificationPipelineBehavior<TBehavior>() -- closed generic
But queries only have:
AddOpenQueryPipelineBehavior(Type) -- open generic only
There is no AddQueryPipelineBehavior<TBehavior>() for registering a closed generic query behavior (e.g., a behavior that only applies to GetUserQuery).
Proposed Solution
Add the missing method to MediatorOptions:
public MediatorOptions AddQueryPipelineBehavior<TBehavior>()
where TBehavior : class
{
var behaviorType = typeof(TBehavior);
if (behaviorType.IsGenericTypeDefinition)
throw new ArgumentException("Open generic types must be registered using AddOpenQueryPipelineBehavior");
var implementsQueryBehavior =
behaviorType.GetInterfaces().Any(i => i.IsGenericType &&
i.GetGenericTypeDefinition() == typeof(IQueryPipelineBehavior<,>));
if (!implementsQueryBehavior)
throw new ArgumentException("Type must implement IQueryPipelineBehavior<,>");
QueryBehaviors.Add(behaviorType);
return this;
}
Also update RegisterPipelineBehaviors in ServiceCollectionExtensions.cs to handle closed query behaviors the same way it handles closed notification behaviors (checking IsGenericTypeDefinition and registering against specific interfaces).
Title: Add
AddQueryPipelineBehavior<T>()for closed generic query behaviorsLabels:
bug,mediatorBody:
Problem
MediatorOptionsprovides closed-generic registration for commands and notifications:AddCommandPipelineBehavior<TBehavior>()-- closed genericAddNotificationPipelineBehavior<TBehavior>()-- closed genericBut queries only have:
AddOpenQueryPipelineBehavior(Type)-- open generic onlyThere is no
AddQueryPipelineBehavior<TBehavior>()for registering a closed generic query behavior (e.g., a behavior that only applies toGetUserQuery).Proposed Solution
Add the missing method to
MediatorOptions:Also update
RegisterPipelineBehaviorsinServiceCollectionExtensions.csto handle closed query behaviors the same way it handles closed notification behaviors (checkingIsGenericTypeDefinitionand registering against specific interfaces).