News for hackers. Stuff that matters.
Re:Minimal APIs at a glance in .NET 6 by andix on Monday September 13, 2021 @09:38AM (#28511318)
Attributes have to be at one specific spot (before the method/class declaration).

Functions and builders you can compose. You can, for example loop, over something and add multiple routes programmatically. For example if you load the routes from a database, it’s really hard to create attributes. You would need to compile and load assemblies on the fly, or do some reflection black magic.

Re:Minimal APIs at a glance in .NET 6 by arethuza on Monday September 13, 2021 @09:41AM (#28511358)
"if you load the routes from a database"

Serious question (honestly not being snarky) - why would you want to do that?

Re:Minimal APIs at a glance in .NET 6 by andix on Monday September 13, 2021 @09:52AM (#28511494)
I don’t know, nobody needs more the 640k of RAM, right?

Maybe you have multiple modules, and depending on the configuration the routing changes. Or feature flags, that enable a breaking api change. Or a stupid customer that pays you a million dollar for custom routes.

But what benefit do the attributes bring? You need to learn them by heart, on builders Intellisense can help you.

Re:Minimal APIs at a glance in .NET 6 by arethuza on Monday September 13, 2021 @10:00AM (#28511593)
Well yes - if you need some kind of dynamically configurable routing then attributes aren't a good fit. I like the fact they are there right next to the relevant method...
Re:Minimal APIs at a glance in .NET 6 by andix on Monday September 13, 2021 @10:05AM (#28511654)
Another thing is, that attributes totally opinionate your code. You pull in a framework into your code.

If you - for example - write one controller you want to use with multiple frameworks (ASP.NET Core or Nancy), you need one controller per framework, just for the attributes.

I always found them more annoying then helpful. Most people seem to see it that way. Most frameworks are moving away from attributes for a good reason.

Re:Minimal APIs at a glance in .NET 6 by aliswe on Monday September 13, 2021 @03:46PM (#28515885)
CMS:s do that! Any kind of editorial content being served is a use case.
Re:Minimal APIs at a glance in .NET 6 by merb on Monday September 13, 2021 @01:59PM (#28514556)
btw. in .net core you can either use attributes or builders to create your routes or even more stuff. at least since (i think) 3.0. and if that is not a great fit you can actually build your own routing by creating a middleware (btw. the endpoint routing stuff is just a middleware)