MediatR
MediatR copied to clipboard
Can't get IPipelineBehavior to work in F#
Doing this in C# works and the behavior is invoked correctly:
public class TestPipeline<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
where TRequest : IBaseRequest
{
public Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssemblies(assemblies);
cfg.AddOpenBehavior(typeof(TestPipeline<,>));
});
Doing this in F#:
type TestPipeline<'TRequest, 'TResponse when 'TRequest :> IBaseRequest>() =
interface IPipelineBehavior<'TRequest, 'TResponse> with
member this.Handle(request: 'TRequest, next: RequestHandlerDelegate<'TResponse>, cancellationToken: CancellationToken) =
task {
return failwith "Not implemented"
}
services.AddMediatR(fun cfg ->
cfg.RegisterServicesFromAssemblies(assembiles) |> ignore
cfg.AddOpenBehavior(typeof<TestPipeline<_,_>>) |> ignore
)
|> ignore
throws
System.ArgumentException: Open generic service type 'MediatR.IPipelineBehavior`2[TRequest,TResponse]' requires registering an open generic implementation type. (Parameter 'descriptors')
What am I supposed to do in F# to add behaviors?