Advertisement
Guest User

Untitled

a guest
Aug 4th, 2024
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. var bld = WebApplication.CreateBuilder(args);
  2. bld.Services
  3.    .SwaggerDocument()
  4.    .AddFastEndpoints()
  5.    .AddLocalization();
  6.  
  7. var app = bld.Build();
  8. app.UseFastEndpoints()
  9.    .UseSwaggerGen()
  10.    .UseRequestLocalization();
  11. app.Run();
  12.  
  13. public partial class Program;
  14.  
  15. sealed class MyRequest
  16. {
  17.     public int Id { get; set; }
  18.  
  19.     public sealed class MyValidator : Validator<MyRequest>
  20.     {
  21.         public MyValidator(IStringLocalizer<MyValidator> localizer)
  22.         {
  23.             RuleFor(r => r.Id).GreaterThan(0).WithMessage(r => localizer["InvalidId"].Value);
  24.         }
  25.     }
  26. }
  27.  
  28. sealed class MyEndpoint : Endpoint<MyRequest>
  29. {
  30.     public override void Configure()
  31.     {
  32.         Post("test");
  33.         AllowAnonymous();
  34.     }
  35.  
  36.     public override async Task HandleAsync(MyRequest r, CancellationToken c)
  37.     {
  38.         await SendAsync(r);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement