question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Minimal API Support

See original GitHub issue

Seeing the recent advancements on the minimal APIs within ASP.NET Core.

It would be really cool if we could look at some extension methods that sit on top of this and provide a way to map IRequest<T> handlers directly to http routes without having to use a controller.

I expect this would be a set of extension methods.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

14reactions
srollinetcommented, Oct 2, 2021

I try to do something similar, with extension methods that allow to map a route to a an IRequest.

Something like that

app.MediatR().MapGet("/hello", (string name) => new HelloQuery(name));

Which will be the equivalent of

app.MapGet("/hello", (string name, IMediator mediator, CancellationToken token) =>
     mediator.Send(new HelloQuery(name), token)
);

The idea is to have something similar as the original API, with less boilerplate.

The problem is that I don’t know the correct approach to use… I tried to create a dynamic delegate that wrap the original one and that adds the mediator and the token, but I don’t think it is a good approach, and I have a lack of knowledge in this domain so I struggled with lot of problems.

Maybe the most simple solution is to have a middleware that handles the IRequest, but with this solution, I don’t know how Swagger will know the actual return type of the method. I will try to dig a bit.

3reactions
srollinetcommented, Aug 8, 2022

@vip32 No, I haven’t done anything. And I will probably wait for asp.net core 7 because the new [AsParameters] attribute will simplify a lot what I want to achieve

https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-dotnet-7-preview-5/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Minimal APIs quick reference
Provides an overview of minimal APIs in ASP.NET Core. ... The minimal APIs consist of: ... can be detected in the service provider....
Read more >
Tutorial: Create a minimal API with ASP.NET Core
In this article Overview Prerequisites Create an API project Add NuGet packages The model and database context classes Add the API code Install...
Read more >
Introduction to ASP.NET Core Minimal APIs
With Minimal APIs, you get a single opportunity to bind data from the request to the model. By default, it's a straightforward deserialization ......
Read more >
Minimal APIs in .NET 6
The core idea behind Minimal APIs is to remove some of the ceremony of creating simple APIs. It means defining lambda expressions for...
Read more >
Minimal APIs in .NET 6
In this article, we are going to explain the core idea and basic concepts of the minimal APIs in .NET 6 with examples....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found