News for hackers. Stuff that matters.
Re:Minimal APIs at a glance in .NET 6 by moogly on Monday September 13, 2021 @12:48PM (#28513686)
There is a multitude of ways in which you could format that code:

  app.MapGet(
      "/todos/{id:int}",
      [Authorize("AdminsOnly")](int id)
          => "This endpoint is for admins only");
Or for people who don't like expression bodied members:

  app.MapGet(
      "/todos/{id:int}",
      [Authorize("AdminsOnly")](int id)
      {
          return "This endpoint is for admins only");
      });
Extracted to a method:

  app.MapGet("/todos/{id:int}", GetTodos);

  [Authorize("AdminsOnly"]
  string GetTodos(int id) => "This endpoint is for admins only";
And more...

You could also put these methods in a class and put the attribute on the class, which would solve your "grouping" problem.

There are no comments on this comment yet.