Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convey.WebApi / invocation of IRequestHandler #35

Closed
b-y-t-e opened this issue Mar 12, 2020 · 7 comments
Closed

Convey.WebApi / invocation of IRequestHandler #35

b-y-t-e opened this issue Mar 12, 2020 · 7 comments

Comments

@b-y-t-e
Copy link

b-y-t-e commented Mar 12, 2020

Hello,
I have a problem with an invocation of simple IRequestHandler. The handler will never get invoked.

public class Program
{
    public static async Task Main(string[] args)
    {
        await WebHost
            .CreateDefaultBuilder(args)
            .ConfigureServices(services => services
                .AddConvey()
                .AddWebApi()
                .Build())
            .Configure(app => app
                .UseEndpoints(endpoints => endpoints
                    .Get("", ctx => ctx.Response.WriteJsonAsync(ctx.RequestServices.GetService<AppOptions>() ) )
                    .Delete<DeleteParcel>("parcels/{parcelId}")))
            .UseLogging()
            .Build()
            .RunAsync();
    }
}
public class DeleteParcel : IRequest
{
    public int ParcelId { get; }
    public DeleteParcel(int parcelId)
    {
        ParcelId = parcelId;
    }
}
public class DeleteParcelHandler : IRequestHandler<DeleteParcel, int>
{
    public async Task<int> HandleAsync(DeleteParcel request)
    {
        return request.ParcelId;
    }
}
@PiotrFerenc
Copy link

change IRequest to ICommand and IRequestHandler to ICommandHandler

@b-y-t-e
Copy link
Author

b-y-t-e commented Mar 15, 2020

Thanks for response, but ICommand does not have any result type, which is crucial for me.

@PiotrFerenc
Copy link

    class CreateOrderHandler : ICommandHandler<CreateOrderCommand>
    {
        public Task HandleAsync(CreateOrderCommand command)
        {
          return Task.FromResult(command.Id);
        }
    }

@b-y-t-e
Copy link
Author

b-y-t-e commented Mar 16, 2020

Thanks for the answer! I know about ICommandHandler and ICommand interfaces (and I use them with no problem). However I would like to bend CQRS assumptions a little, and I would like that commands are able to return the value to the client. According to the documentation (https://convey-stack.github.io/documentation/Web-API/) IRequestHandler interface is ideal for this scenario, but the example from documentation does not work.

@Allann
Copy link

Allann commented Mar 23, 2020

I understand the frustration, I recently swapped in MediatR (https://www.nuget.org/packages/MediatR/) with success, maybe if you are blocked this could be a solution?.

@GooRiOn
Copy link
Member

GooRiOn commented Nov 8, 2020

Neither of the CQRS packages provide you such thing, however there's the IRequestHandler<,> type beeing provided by WebAPI package along with its internal registration:

https://github.com/snatch-dev/Convey/blob/5b9a36606bad36d071461d984413f3c4e5adeca6/src/Convey.WebApi/src/Convey.WebApi/Requests/IRequestHandler.cs

builder.Services.Scan(s =>

@GooRiOn GooRiOn closed this as completed Nov 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants