News

ASP.NET Core Furthers Minimal API Work in .NET 7 Preview 3

One of the highlights of improved ASP.NET Core functionality in .NET 6 was support of minimal APIs, for which work is still ongoing in the new .NET 7 Preview 3.

Minimal APIs are architected to create HTTP APIs with minimal dependencies, says Microsoft, which notes they are ideal for microservices and ASP.NET Core apps in which developers want to include only the minimum files, features and dependencies.

In .NET 7 Preview 3 there is new support for route handler filters in minimal APIs, along with improved unit testability for minimal route handlers.

"In this preview, we introduce support for filters in route handlers in minimal applications," said Daniel Roth, principal program manager, in an April 12 blog post. "Filters are executed before the core route handler logic and can be used to inspect and modify handler parameters or intercept handler execution.

"Filters can be registered onto a handler using a variety of strategies. For example, you can register a filter using a RouteHandlerFilterDelegate and the AddFilter extension method."

As far as improved unit testability for minimal route handlers, Roth said IResult implementation types are now publicly available in the namespace Microsoft.AspNetCore.Http with the suffix HttpResult (OkObjectHttpResult, ProblemHttpResult and so on). He said this helps developers more easily unit test minimal route handlers when using named methods instead of lambdas.

Minimal API Work in .NET 7
[Click on image for larger view.] Minimal API Work in .NET 7 (source: Microsoft).

The ASP.NET Core Roadmap for .NET 7 provides more information on what work remains, including for minimal APIs (shown above).

Other highlights of the preview as called out by Roth include:

  • Developer exception page dark mode: Developers can now enjoy a new dark mode when reading about unhandled exceptions:
    Developer Exception Page Dark Mode
    [Click on image for larger view.] Developer Exception Page Dark Mode (source: Microsoft).
  • Bind using TryParse in MVC and API controllers: Developers can now bind controller action parameter values using a TryParse method that has one of two signatures.
  • New Results.Stream() overloads: These are for scenarios where developers need access to the underlying HTTP response stream without buffering. "These overloads also improve cases where your API wants to stream data to the HTTP response stream, like from Azure Blob Storage."
  • Improved HTTP/2 performance when using many streams on a connection: "We made a change in our HTTP/2 frame writing code that improves performance when there are multiple streams trying to write data on a single HTTP/2 connection. We now dispatch TLS work to the thread pool and more quickly release a write lock that other streams can acquire to write their data. The reduction in wait times can yield significant performance improvements in cases where there is contention for this write lock."
  • New ServerReady event for measuring startup time: Coders using EventSource for metrics/diagnostics who want to measure ASP.NET Core app startup times can now use the new ServerReady event in the Microsoft.AspNetCore.Hosting source, which represents the point where the server is up and running.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube