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 for Converge360.

comments powered by Disqus

Featured

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube