jbogard / MediatR

Simple, unambitious mediator implementation in .NET
Apache License 2.0
10.84k stars 1.15k forks source link

Can't get IPipelineBehavior to work in F# #1004

Closed atlemann closed 2 months ago

atlemann commented 4 months ago

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?

jbogard commented 4 months ago

No idea, I don't do F#.

github-actions[bot] commented 2 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] commented 2 months ago

This issue was closed because it has been stalled for 14 days with no activity.