Reputation: 63
I have searched on the Internet, and I couldn't find a concrete explanation regarding this.
I have used the Minimal API before, and when I am using the .NET AOT, the project source code seems different except for the endpoints are still in the Program.cs file.
Upvotes: 2
Views: 423
Reputation: 141565
Native AOT for ASP.NET Core was added with .NET 8 - check out the corresponding section of the What's new in ASP.NET Core 8.0 doc.
ASP.NET Core support for Native AOT doc covers the feature in more detail. First of all you should notice Minimal APIs are supported partially (and MVC is not supported at all):
Feature | Fully Supported | Partially Supported | Not Supported |
---|---|---|---|
gRPC | ✔️Fully supported | ||
Minimal APIs | ✔️Partially supported | ||
MVC | ❌Not supported | ||
Blazor Server | ❌Not supported | ||
SignalR | ❌Not supported | ||
JWT Authentication | ✔️Fully supported | ||
Other Authentication | ❌Not supported | ||
CORS | ✔️Fully supported | ||
... | ... | ... | ... |
The main difference in the template itself comes from the fact that reflection APIs are not supported in the Native AOT so you need to switch to source generation for System.Text.Json
(see the Minimal APIs and JSON payloads section of the docs too):
builder.Services.ConfigureHttpJsonOptions(options => { options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default); }); [JsonSerializable(typeof(Todo[]))] internal partial class AppJsonSerializerContext : JsonSerializerContext { }
Without this added code,
System.Text.Json
uses reflection to serialize and deserialize JSON. Reflection isn't supported in Native AOT.
The second noticable difference is usage of CreateSlimBuilder
method instead of CreateBuilder
. For more details see the CreateSlimBuilder
vs CreateBuilder
section of the docs.
Upvotes: 1
Reputation: 656
Different but can be used together. Minimal API has to do with streamlining HTTP calls and AOT creates machine code. AOT can take the Minimal API code along with the rest of the app/DLL and create machine code.
Upvotes: 1