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.

Content for Minimal APIs scaffolding with .NET 7 features

See original GitHub issue

The team will be rolling out a number of features for .NET 7, some of which we want to include in our scaffolding to make the new functionalities more easily adopted.

Existing scaffolded items include:

  • Minimal API with read/write endpoints
  • Minimal API with read/write endpoints (with OpenAPI)
  • Minimal API with endpoints, using Entity Framework
  • Minimal API with endpoints, using Entity Framework (with OpenAPI)

List of our .NET 7 features:

  • Route groups: allows devs to relate their endpoints by putting them into the same group which can be decorated with metadata
  • Endpoint filters: allows users to implement parameter validation or custom response processing
  • Results API improvements: easier testing and interacting
  • Improved OpenAPI integration: support for endpoint metadata providers

Ideas for scaffolded items:

  • Minimal API with a route group
  • Minimal API with a route group (with OpenAPI)
  • Minimal API with endpoints, using filters
  • Minimal API with endpoints, using filters (with OpenAPI)
  • Minimal API with endpoints, using Result API
  • Minimal API with endpoints, using Result API (with OpenAPI)
  • Minimal API with endpoints (with OpenAPI using an endpoint metadata provider)
  • ideas from EF team, C# folks, etc.

From the previous minimal API issue:

When OpenAPI is opted-in to, the required packages and startup configuration code should be applied to the project.

For the items using Entity Framework, just like the existing Web API scaffolders, the user can select to have a DbContext created or select an existing DbContext. The appropriate packages and startup configuration code should be applied to project for Entity Framework based on the user’s selection.

In lieu of selecting a controller name, the user will select a class name that will contain the generated endpoint mapping code. If the class doesn’t exist, a new static class will be created and the extension method added to it. If the class already exists, it must be static, and the extension method will be added to it. The name of the class will default to [ModelClass]Endpoints, e.g. given model class Widget the class will be named WidgetEndpoints. The static method will be named Map[ModelClass]Endpoints, e.g. given model class Widget the method will be names MapWidgetEndpoints.

The application startup code should be updated by the scaffolder to call the generated extension method that maps the endpoints.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
DamianEdwardscommented, Mar 8, 2023

I think the speclet there was based on an earlier design of route groups. Whatever the scaffolding produces now is what we’d recommend you use as a starting point.

1reaction
captainsafiacommented, Aug 29, 2022

Does it make sense to make the return type for these a RouteGroupBuilder or IEndpointRouteBuilder so that users can continue to modify the output? It seems to align more cleanly to me with the other builder patterns we have.

public static void MapWidgetEndpoints(this IEndpointRouteBuilder routes)

WithOpenApi integration in these looks good. One thing to note is that it’ll depend on RC1 since we did some work to fix up route groups + WithOpenApi in RC1.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Build Minimal APIs In .NET 7 Using Entity Framework Core 7
This article describes how we can build Minimal APIs in .NET 7 using Entity Framework Core 7 with an example and code details....
Read more >
Exploring Minimal APIs in .NET 7: Advantages and ...
With Minimal APIs, the focus is on the essential functionality of your API, while the framework handles common tasks such as routing, dependency ......
Read more >
Tutorial: Create a minimal API with ASP.NET Core
Learn how to build a minimal API with ASP.NET Core. ... API project based on controllers that contains more features, see Create a...
Read more >
What's New in .NET 7 for Minimal APIs?
NET 7 arrived and brought three great features to minimal APIs. Check out in this blog post what's new with practical examples.
Read more >
7 Awesome New Features in .NET 7 - YouTube
NET 7. From improved performance to new features for building and managing ... NET Core 06:20 - Minimal API Grouping 09:10 - C#...
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