3

Is the ASP.NET Core 6 minimal API supposed to create a smaller app compared to the classic controller based approach?

From the Microsoft documentation

Minimal APIs are architected to create HTTP APIs with minimal dependencies. They are ideal for microservices and apps that want to include only the minimum files, features, and dependencies in ASP.NET Core.

But when you create two default apps in Visual Studio, one minimal and one controller based (both containing the same default Weather forecast endpoint) and publish the apps, they are pretty much the same size. Publishing as framework dependent apps, both end up at just around 4 MB.

Am I missing something here? I would expect the minimal API to be smaller.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Q-bertsuit
  • 3,223
  • 6
  • 30
  • 55
  • There might be a (nearly immeasurable) difference between the two app sizes based on the size of _YOUR_ code, but that will absolutely be dwarfed by the sheer magnitude of the dependencies required to run your application in nearly all cases. – David L Oct 17 '22 at 20:19
  • But it's not my code though, its the starting code provided by Microsoft. The controller example uses ControllerBase and the Route and ApiController attributes and so forth. If the answerer is that when the app grows, the minimal API will typically be smaller, I'll accept that – Q-bertsuit Oct 17 '22 at 20:24
  • Note that in addition to @DavidL comment - in theory Minimal API app can require less dependencies and with addition of assembly trimming (should be [enabled by default in .NET 7](https://learn.microsoft.com/en-us/dotnet/core/compatibility/deployment/7.0/trim-all-assemblies)) can result in lesser app size if deployed as self-contained/single file app. – Guru Stron Oct 17 '22 at 21:05
  • @Q-bertsuit, I believe that the benefit is exactly what Guru Stron's comment refers to. – David L Oct 17 '22 at 22:14

1 Answers1

5

I haven't seen an official explanation but would assume the term minimal refers to the amount of boilerplate and ceremony rather than the actual binary filesize.

Oliver Weichhold
  • 10,259
  • 5
  • 45
  • 87
  • That makes sense, it's just that the introduction text in the docs makes it sound like it's also related to the size of the app. – Q-bertsuit Oct 17 '22 at 20:16